[Android Software/Hacking General [Developers Only]] Lycan:
Basic Linux/Unix Commands

[HIGHLIGHT] DISCLAIMER - You know the drill. I don't deem myself responsible in case you screw up your phone. Always make a backup if you don't trust yourself and if you know that you screwing up is your forte[/HIGHLIGHT] :)

Thanks -

mihir287 for his FAQ

sweetnsour for his extensively detailed thread

Shen - advice

Zayed from www.addictivetips.com

http://www.linuxtopia.org

This guide aims to give you a background on some of the linux commands available to you once you obtain an adb shell.

In order to obtain an ADB shell, you must have adb set up on your computer (all ADB really consists of in windows is adb + 2 dlls + adb drivers.

However it makes sense to fully set up the Android SDK if you plan on developing for Android.

You need to install adb or get Terminal Emulator. To install adb and get more info about it visit here.

NOTE = All commands in linux/unix are

CASE SENSITIVE

.

Shell Commands

These commands are to be typed after typing

adb shell

In the Command Prompt.

Or, you can proceed normally if you are using a Terminal Emulator.

1.

cd - Change Directory

To change to any directory, simply type:

cd <dirname>

dir name is the path. For instance, to switch to system/etc, type:

cd /system/etc

'..' will allow you to go back one directory. In our example, typing:

cd ..

would take you back to /system

2.

ls - List Files

To list all the files in whatever directory you're in, simply type:

ls

pressing enter after, of course. This will list all NON-HIDDEN files/directories.

ls /system/etc

will list the contents of system/etc

ls -l

will list all NON-HIDDEN files in your current directory with additional details

ls -a

will list all files/directories(including hidden) within your current directory

ls *.extension

will list all the files wit the specified extension in the directory

For example i wanna list all apps -

cd /system/app
ls *.apk

3.

su - SuperUser

The standard adb shell (unless you're on an insecure kernel/ramdisk), will be a non-root shell ($)

To obtain root priviliges (if your phone is rooted), simply type:

su

on obtaining superuser priviliges, you will be presented with a # symbol, which represent a root shell.

4.

chmod - Change Mode

The two most commonly used 'modes' you'll come across in Android are '777' and '755'

These numerical pemissions have different meanings, of course. This can be a little confusing, so I hope this explains it in a simple to understand way.

As you can see, there are three numbers in the following example; 'chmod 755'

So, to break that down: The first number in the sequence, '7', represents the USER (aka, you). The second number in the sequence, '5', represents the GROUP (users who are members of the file's group) and the third number, '5' represents OTHERS (aka, everyone else).

Now to explain why they are 755, and the significance of those numbers, see the following list:

7 Full

6 Read/Write

5 Read/Execute

4 Read Only

3 Write/Execute

2 Write Only

1 Execute

0 None

So in the instance of 777, you can see that USER, GROUP and OTHERS have FULL access to the file in question.

To change the permissions of one file (apns-conf.xml for example, type:

chmod 777 /system/etc/apns-conf.xml

To change the permissions of all files in a directory, use the -R (recursive)option:

chmod 777 -R /system/etc

5.

pwd - Print Working Directory

Couldn't be more simple. if you want to find out which dirctory you're currently in, type:

pwd

and press enter.

6.

cat - Concatenate (evolved from)

The cat command if used to list a file's contents on your screen; or pass via pipeline to use with other Linux commands.

cat /proc/mounts

will output the various mount points in your android OS.

Note that there are many other uses for the cat command.

7.

mount - remount as r/w or r/o

The mount command is used to mount a directory as r/w[Read-Write which allows you to modify it] or r/o[Read-Only]

Mount info -

mount

To mount as r/w and r/o respectively use -

mount -o remount rw <dirname>
or
mount -o remount ro <dirname>

To mount /system i will use

mount -o remount rw /system
or
mount -o remount ro /system

8.

cp, mv, rm - Copy, Move, Remove

Use the 'cp' and 'mv' commands to copy, move a file/directory respectively and 'rm' to remove one. They are equivalent to copy+paste and cut+paste and delete

If you are planning to copy/move/remove from your android to anywhere else or viceversa you need to mount as r/w prior to this and mount as r/o after it.

They can be used as

cp <source> <destination>
or
mv <source> <destination>
or
rm <source>

For example i wanna copy/move/delete my zip file to system/media [after mounting system]

cp /sdcard/bootanimation.zip system/media
or
mv /sdcard/bootanimation.zip system/media
or
rm /sdcard/bootanimation.zip

9.

Auto - Install Applications To SDCard

Type the following -

pm setInstallLocation 2

10.

logcat

A logcat is basically a command to view messages in one of the system logs.

Logcat is the command to view the internal log of the Android system.

Viewing logcat is often the best way - and sometimes the only way - to diagnose a problem.

Dev's always need proper and useful feedback. So if you are testing something, you can always obtain the errors an report back to the dev who in turn can solve your problem efficiently.

su
logcat > /sdcard/log.txt

Will obtain the logcat to your sdcard as log.txt

Googlers have a sense of humour ;) so even 'lolcat' works identically as 'logcat'

lolcat

Some dev's require extensive logcat info. To know more about it continue reading here.