Linux Commands on Android

Discussion in 'Android Hacks and Help' started by christim, Feb 26, 2010.

  1. christim

    christim DF Super Moderator Rescue Squad

    Joined:
    Jan 23, 2010
    Messages:
    5,100
    Likes Received:
    2
    Trophy Points:
    153
    Location:
    New England
    Ratings:
    +2
    I thought I'd start a thread on what some of the commands mean people are typing when rooted and see if there was any interest in this. I searched but did not find a similar thread but if there is let me know. I'll also include some other commands you can try out that you may not have used, especially if you are not familar with Linux or Unix.

    These are typed in the terminal emulator, available for free from the market place as Android Terminal Emulator. Once downloaded it shows as Terminal Emulator in your app drawer.

    Don't just randomly try commands. Some delete things so know what you are doing.

    • chmod - give/take rights away from files. The numbers you see in the how-to's is a little complicated. It has to do with the rights you are assigning the file or folder. http://wiki.linuxquestions.org/wiki/Chmod for further reading.
    • cat - look at, modify, or combine a file. You can also copy files with this command by "reading" it to another file instead of to the screen.
    • cd - change from one directory to another
    • cp - Copy a file from one location to another
    • dd - copies exact locations to other locations. Can be an entire drive, a folder, etc. dd if=<file directory> of=<other directory>. uses an input file and an output file.
    • exit - exits the shell you are in. When you type su you start up a shell.
    • ls - lists all files with in a directory try ls - l too.
    • mv - Move a file from one location to another. At the same time you can rename a file.
    • su - Substitute User. We type this to switch to the root user. You need to type this command first to do a lot of the other commands.
    • tar - creates taped archives. Compresses files like winzip, 7zip, winrar and others tar /? for details.
    • rm - followed by a file name with delete the file
    • sync - synchronizes any data on disk with data in memory. We type this before rebooting to ensure we've got all data written
    Other commands of interest:


    • df - how much free disk space. In linux you can add a switch "df -h" but the "-h" does nothing for me on Android.
    • top - like task manager, it displays running processes. in Linux the q key quits. On Android I don't know how to make it quit other than closing the app.
    • uptime - displays how long it has been since you last rebooted the system. Interestingly enough the "Menu Key > System > About Phone > Status > Up time" on my phone does not match "uptime" typed in the terminal emulator.


    • busybox - a tool that combines many linux commands into a single compact file. Typing this displays all the commands at your disposal.
      • busybox df - a much easier to read display of free diskspace. This display shows how full (use%) each file system is.
        • Search the internet for what some of the other busybox commands do by just searching for something like "linux df".

    If there are other good commands of interest post them here and I'll add them to this. Searching the internet will show you others as well.

    You also can put a /? after the command so ls /? will display options. ls -l will do a long list vs the list short view
     
    • Like Like x 1
  2. thebowers

    thebowers Premium Member Theme Developer Premium Member

    Joined:
    Nov 24, 2009
    Messages:
    2,547
    Likes Received:
    1
    Trophy Points:
    101
    Location:
    Iowa
    Ratings:
    +1
    Here is some more

    ls - lists all files with in a directory
    rm - followed by a file name with delete the file

    there are many other commands and you can also make custom ones to shorten commands.

    Edit: I think your first command is suppose to be chmod
     
  3. adrynalyne

    adrynalyne Premium Member Premium Member Developer

    Joined:
    Dec 21, 2009
    Messages:
    2,896
    Likes Received:
    4
    Trophy Points:
    103
    Ratings:
    +4

    chmode should be chmod.

    Many of these commands require busybox to not only be installed, but used in the command, unless you symlink the commands.

    For example, cp would be used as busybox cp.
     
  4. adrynalyne

    adrynalyne Premium Member Premium Member Developer

    Joined:
    Dec 21, 2009
    Messages:
    2,896
    Likes Received:
    4
    Trophy Points:
    103
    Ratings:
    +4
    cat can also be used to rename/move files.
    tar is used as a command line compress/decompress utility.
     
  5. christim

    christim DF Super Moderator Rescue Squad

    Joined:
    Jan 23, 2010
    Messages:
    5,100
    Likes Received:
    2
    Trophy Points:
    153
    Location:
    New England
    Ratings:
    +2
    Right you are..I fixed "chmod", thanks. I was a little worried posting the rm command but if you have a backup you are all set. There's some recursive stuff that I won't be posting though :)

    I'm used to the up-arrow at a command prompt scrolling through your history of commands. I don't know if that's terminal emulator not passing it through (d-pad?) or if this version of Linux just doesn't support it.

    uname -a will display the version of Linux you are running.
    for me it says:
    2.6.29-Smoked_Glass #9
    I'm running the SG4.5 rom at the moment.
     
  6. christim

    christim DF Super Moderator Rescue Squad

    Joined:
    Jan 23, 2010
    Messages:
    5,100
    Likes Received:
    2
    Trophy Points:
    153
    Location:
    New England
    Ratings:
    +2
    two good ones. cat is one used in instructions here too. dd is another one I just added as well, thanks!

    cat is an interesting one to use for copying because it normally is used for viewing a file. By redirecting that viewing to another file, instead of defaulting to the screen we read the contents into another file...thus making a copy
    cat file1.txt > file2.txt
     
  7. christim

    christim DF Super Moderator Rescue Squad

    Joined:
    Jan 23, 2010
    Messages:
    5,100
    Likes Received:
    2
    Trophy Points:
    153
    Location:
    New England
    Ratings:
    +2
    hey hey hey...this is a family rated site :)

    Do you have an example of where you saw this in use? It is not a command I am familar with and when I try to FU it says "not found" so it isn't installed on my phone.
     
  8. h1br1d7heory

    h1br1d7heory Member

    Joined:
    Feb 18, 2010
    Messages:
    70
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Long Island
    Ratings:
    +0
    I am trying to use chmod so I can write to /system/app.

    I have tried the following with the following results:

    chmod 755 /system/app
    Unable to chmod /system/app: Read-only file system


    The goal: I am trying to move some .apk files from my sdcard into that folder.

    Can someone tell me what I am doing wrong?
     
  9. gustofusion

    gustofusion New Member

    Joined:
    Aug 10, 2010
    Messages:
    2
    Likes Received:
    1
    Trophy Points:
    3
    Ratings:
    +1



    run this fro a terminal then you can chmod

    mount -o remount,rw -t ext3 /dev/block/mmcblk1p21 /system
     
    • Like Like x 1
  10. Se7enLC

    Se7enLC Active Member

    Joined:
    Nov 16, 2009
    Messages:
    1,262
    Likes Received:
    0
    Trophy Points:
    36
    Ratings:
    +0
    Good idea to put this all in one place!

    The "-h" on df is to display in "human readable" format - ie, it splits sizes up into kb, mb, gb instead of just showing a really large number of kb. I believe some versions use this mode by default, so the -h may be unnecessary.

    /? is for windows and does nothing for linux commands. In linux, the parameter is usually -h, or --help, and sometimes -?. Always a dash, though, never a slash.

    Some other useful commands:
    du - show disk usage of files. Add "-h" to get human readable. Especially useful when you add "-d1" to limit the directory depth to 1. If you run "du -h -d1", it will tell you how much space each directory occupies, including their contents summed.

    rmdir - remove a directory. rm can't do it unless you remove recursively with -R
    pm - android package manager. LOTS of useful things in here, type pm by itself for the help screen
    ps - list processes. Useful to see what is running
    kill - kill a process by PID
    top - graphical display of processes, including cpu and memory use. hit 'q' to exit.
    reboot - reboot
    grep - search within a file for a text string. Also useful for parsing command output. 'ls | grep something' is a quick way to list files that contain the string "something" (although "ls *something*" would do it, too, but grep can do a lot more)
    ping - see if an internet host is alive
    ifconfig - get network interface configuration. Good for getting your own IP address.
     
  11. jeffe65

    jeffe65 Member

    Joined:
    Mar 8, 2010
    Messages:
    197
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Phoenix, AZ
    Ratings:
    +1
    Anybody know if there's a way to start a program on boot using commands, or does it have to be set within the program itself? I'm using AutoKill, and it works great, but you have to set it back to your preferences after reboot.
     
  12. solar

    solar Member

    Joined:
    Dec 8, 2009
    Messages:
    798
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    So Cal
    Ratings:
    +0
    I just came across this thead. Pretty cool stuff. I"m always interested in learning more about android.
     
  13. knuckleheadTech

    knuckleheadTech New Member

    Joined:
    Dec 9, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Idaho USA
    Ratings:
    +0
    I do love some good command line lovin'. Thank you for posting this. If anyone has more keep it coming.
     
  14. Jsk19

    Jsk19 New Member

    Joined:
    May 26, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    busybox and uptime do not work for me =(
     
  15. contractorslim

    contractorslim Member

    Joined:
    May 13, 2011
    Messages:
    55
    Likes Received:
    0
    Trophy Points:
    6
    Ratings:
    +0
    Just curious does anyone know what a command used to download a file? I'm trying to partition my sd card and found a way using the following command via code.google.com

    $ su
    # cd /data
    # wget http://64.105.21.209/bin/lib/droid/sdsplit
    # chmod 555 sdplit
    # exit

    I get wget: not found.

    Is there any way to use a different command from terminal emulator to download the executeable? I tried through a browser but it looks like a script...showing source code only. Maybe everyone can help me out.
     
Search tags for this page
android command
,
android command line
,

android commands

,

android linux commands

,

android terminal commands

,
android terminal commands list
,

android terminal emulator commands

,
terminal emulator android commands
,
terminal emulator android commands list
,
terminal emulator commands android