Tuesday, May 13, 2014

[GUIDE] Basic Unix/Linux command to use with ADB SHELL..//

Basic Unix/Linux command to use with ADB SHELL

You must know how to invoke a adb shell command already to drop into your phone.
ALL commands in Unix/Linux are case sensitive

For more details, go to this ADB tutorial (very good one).

Let's get going:

Once a shell is gained via adb, let's look at some of the basic commands you can do to navigate around the filesystem. Note: you must remove the double-quotes (") for the actual command.

"cd" = is change directory


Code:
to change to any directory, you type:  cd dir_name (where dir_name is a full path)

Example: I want to go to /data/local/tmp in my phone, I would do

cd /data/local/tmp <hit ENTER>

You can also use the ".." to go UP one directory.

Example: I'm in /data/local/tmp and I want to go up to /data folder, a command would be:  cd ../..  alternatively, if I do cd .. then i'll drop into /data/local folder instead.
"ls" = list files/directories

Code:
to list files/directories within a folder, the command should be:

ls <hit enter>  => this will list all NON-HIDDEN file/directories within your CURRENT directory.

ls /data/local/tmp => this will list all NON-HIDDEN file/directories within /data/local/tmp directory.

ls -l => this will list all NON-HIDDEN file/directories within your CURRENT directory, plus additional details.  Consider this is like a "Details" view in Windows Explorer.

ls -a => this will list all files/directories (including hidden files) within your CURRENT directory.

ls -la => this will list all files/directories (including hidden files) within your CURRENT directory, plus details.
"chmod" = change mode

Code:
Goes to wikipedia for more details: https://secure.wikimedia.org/wikipedia/en/wiki/Chmod

Most commonly used modes on android phones are:

"755" or "777".

So if you have a root.sh shell script that you downloaded from XDA, and uploaded to your phone and try to execute it with ./root.sh and it said "Permission denied".  That means your script does not have the execute permission.  You need to do:

chmod 755 root.sh <hit enter>

IMPORTANT: There is *NO* negative sign (-) in front of the mode bit.  So it is NOT chmod -755 root.sh

If you get a "File or directory not found" error, which means you are chmod-ing a file that doesn't exist in your current directory.  To execute a chmod on root.sh in /data/local/tmp you do:

chmod 755 /data/local/tmp/root.sh

If you want to chmod an ENTIRE DIRECTORY and ALL files underneath it you do:

chmod -R 755 /data/local/tmp => this will set /data/local/tmp and ALL files/folders underneath it to be 755.
"chown" = change ownership

Code:
Go to wikipedia for details: https://secure.wikimedia.org/wikipedia/en/wiki/Chown

Most common used chown for android is: "root:root" or "root:shell"

Example: if you want to change ownership of root.sh to root:shell then you do:

chown root:shell root.sh

NOTE: the -R (recursive) option is also available for chown.

chown -R root:shell /data/local/tmp
"pwd" = print working directory

Code:
so when you are within a directory and you want to know which directory you are in, then you issue the command:

pwd <hit enter>

The system will reply back with the currently directory you are in.

No comments:

Post a Comment