2012年10月18日 星期四

Android / Linux Shell Command List


Preface

We've discussed about the Android / Linux Command in separate article. Here, we want to talk about what we can use and where to find the useful commands in Android device. Connect your Android device and launch a command line window in advance. Then you can try to use all these commands by executing command adb shell command_name.

The following commands can be found in the folder "/system/bin/ on Nexus 7.


Commands Desc.
adb Android Debug Bridge
am Activity Manager
app_process Execute a runtime environment for a dalvik class/Jar file.
applypatch Apply patches to android files.
usage: applypatch [: ...]
   or  applypatch -c [ ...]
   or  applypatch -s
   or  applypatch -l

Filenames may be of the form
  MTD::::::...
to specify reading from or writing to an MTD partition.
atrace Trace information captured in the folder of /sys/kernel/debug/tracing/
usage: atrace [options]. Measure the system performance and do the analysis. Systrace tool provides more parameters to measure the performance than atrace.
options include:
  -b N            use a trace buffer size of N KB
  -c              trace into a circular buffer
  -d              trace disk I/O
  -f              trace CPU frequency changes
  -l              trace CPU frequency governor load
  -s              trace the kernel scheduler switches
  -t N            trace for N seconds [defualt 5]
  -w              trace the kernel workqueue
  -z              compress the trace dump
bluetoothd Bluetooth Debuging Utility
Usage:
  bluetoothd [OPTION...]

Help Options:
  -?, --help                  Show help options

Application Options:
  -d, --debug=DEBUG           Specify debug options to enable
  -p, --plugin=NAME,..,       Specify plugins to load
  -P, --noplugin=NAME,...     Specify plugins not to load
  -n, --nodetach              Don't run as daemon in background
  -v, --version               Show version information and exit
  -u, --udev                  Run from udev mode of operation
bmgr bmgr is a shell tool you can use to interact with the Backup Manager on Android devices.
usage: bmgr [backup|restore|list|transport|run]
       bmgr backup PACKAGE
       bmgr enable BOOL
       bmgr enabled
       bmgr list transports
       bmgr list sets
       bmgr transport WHICH
       bmgr restore TOKEN
       bmgr restore TOKEN PACKAGE...
       bmgr restore PACKAGE
       bmgr run
       bmgr wipe PACKAGE
bootanimation Show the boot animation.
brcm_patchram_plus This program downloads a patchram files in the HCD format to Broadcom Bluetooth based silicon and combo chips and and other utility functions.
It can be invoked from the command line in the form
 <-d> to print a debug log
 <--patchram patchram_file="patchram_file">
 <--baudrate baud_rate="baud_rate">
 <--bd_addr bd_address="bd_address">
 <--enable_lpm>
 <--enable_hci>
 uart_device_name
btmacreader Bluetooth MAC Reader.
bu Backup
Options:
   -apk,   Save APK
   -noapk,  Save no APK
   -shared,  Save Shared
   -noshared, Save no Shared
   -system,  All Includes System
   -nosystem,  Not all Includes System
   -all,   Everything
bugmailer.sh Send Bug Report to Vendor.
bugreport Export all the debug message from Android and Linux layer.
cat -> toolbox Concatenate, a tool to print out the content of a file continually. It's the same usage with Linux.
chmod -> toolbox Change the mode of file. Usage is the same with Linux.
chown -> toolbox Change the owner of a file/folder. Usage is the same with Linux.
cmp -> toolbox Compare the file. Usage is the same with Linux.
content Perform operations on particular content
usage: adb shell content [subcommand] [options]
usage: adb shell content insert --uri --bind [--bind ...]
  a content provider URI.
  binds a typed value to a column and is formatted:
  :: where:
  specifies data type such as:
  b - boolean, s - string, i - integer, l - long, f - float, d - double
  Note: Omit the value for passing an empty string, e.g column:s:
  Example:
  # Add "new_setting" secure setting with value "new_value".
  adb shell content insert --uri content://settings/secure --bind name:s:new_setting --bind value:s:new_value

usage: adb shell content update --uri [--where ]
  is a SQL style where clause in quotes (You have to escape single quotes - see example below).
  Example:
  # Change "new_setting" secure setting to "newer_value".
  adb shell content update --uri content://settings/secure --bind value:s:newer_value --where "name='new_setting'"

usage: adb shell content delete --uri --bind [--bind ...] [--where ]
  Example:
  # Remove "new_setting" secure setting.
  adb shell content delete --uri content://settings/secure --where "name='new_setting'"

usage: adb shell content query --uri [--projection ] [--where ] [--sort ]
  is a list of colon separated column names and is formatted:
  [:...]
  is the order in which rows in the result should be sorted.
  Example:
  # Select "name" and "value" columns from secure settings where "name" is equal to "new_setting" and sort the result by name in ascending order.
  adb shell content query --uri content://settings/secure --projection name:value --where "name='new_setting'" --sort "name ASC"
dalvikvm Launch the Dalvik VM to run a Java class in DEX format.
dalvikvm: [options] class [argument ...]
dalvikvm: [options] -jar file.jar [argument ...]

The following standard options are recognized:
  -classpath classpath
  -Dproperty=value
  -verbose:tag  ('gc', 'jni', or 'class')
  -ea[:... |:]
  -da[:... |:]
   (-enableassertions, -disableassertions)
  -esa
  -dsa
   (-enablesystemassertions, -disablesystemassertions)
  -showversion
  -help

The following extended options are recognized:
  -Xrunjdwp:
  -Xbootclasspath:bootclasspath
  -Xcheck:tag  (e.g. 'jni')
  -XmsN  (min heap, must be multiple of 1K, >= 1MB)
  -XmxN  (max heap, must be multiple of 1K, >= 2MB)
  -XssN  (stack size, >= 1KB, <= 256KB)
  -Xverify:{none,remote,all}
  -Xrs
  -Xint  (extended to accept ':portable', ':fast' and ':jit')

These are unique to Dalvik:
  -Xzygote
  -Xdexopt:{none,verified,all,full}
  -Xnoquithandler
  -Xjnigreflimit:N  (must be multiple of 100, >= 200)
  -Xjniopts:{warnonly,forcecopy}
  -Xjnitrace:substring (eg NativeClass or nativeMethod)
  -Xstacktracefile:
  -Xgc:[no]precise
  -Xgc:[no]preverify
  -Xgc:[no]postverify
  -Xgc:[no]concurrent
  -Xgc:[no]verifycardtable
  -XX:+DisableExplicitGC
  -X[no]genregmap
  -Xverifyopt:[no]checkmon
  -Xcheckdexsum
  -Xincludeselectedop
  -Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*
  -Xincludeselectedmethod
  -Xjitthreshold:decimalvalue
  -Xjitblocking
  -Xjitmethod:signature[,signature]* (eg Ljava/lang/String\;replace)
  -Xjitcheckcg
  -Xjitverbose
  -Xjitprofile
  -Xjitdisableopt
  -Xjitsuspendpoll

Configured with: debugger profiler hprof jit(armv7-a) show_exception=1

Dalvik VM init failed (check log file)
date -> toolbox Set date value.
date -s yyyymmdd, set date on Android
dd -> toolbox Copy, Convert, and Format a file.
Usage: dd [options]
   bs=BYTES [block size]
   cbs=BYTES [conversion record size]
   conv=KEYWORDS [conv option disabled]
   count=BLOCKS [block count]
   ibs=BYTES [input block size]
   if=FILE [read file]
   obs=BYTES [output block size]
   of=FILE [write file]
   seek=BLOCKS [seek blocks]
   skip=BLOCKS [skip blocks]
Ex: dd if=/data/local/tmp/1gb bs=64k | dd of=/sdcard/1gb
df -> toolbox List free space on disk
dmesg -> toolbox Output linux debug message
dumpstate Dump system status
usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s]
  -o: write to file (instead of stdout)
  -d: append date to filename (requires -o)
  -z: gzip output (requires -o)
  -p: capture screenshot to filename.png (requires -o)
  -s: write output to control socket (for init)
  -b: play sound file instead of vibrate, at beginning of job
  -e: play sound file instead of vibrate, at end of job
dumpsys Dump functional state
dumpsys [options]
Execute dumpsys will output all the message in case there's no option specified.
option:
  accessibility
  account
  activity
  alarm
  appwidget
  audio
  backup
  battery
  batteryinfo
  bluetooth
  bluetooth_a2dp
  clipboard
  commontime_management
  connectivity
  content
  country_detector
  cpuinfo
  dbinfo
  device_policy
  devicestoragemonitor
  diskstats
  drm.drmManager
  dropbox
  entropy
  gfxinfo
  hardware
  input
  input_method
  iphonesubinfo
  isms
  location
  lock_settings
  media.audio_flinger
  media.audio_policy
  media.camera
  media.player
  meminfo
  mount
  netpolicy
  netstats
  network_management
  nfc
  notification
  package
  permission
  phone
  power
  samplingprofiler
  scheduling_policy
  search
  sensorservice
  serial
  servicediscovery
  simphonebook
  sip
  statusbar
  SurfaceFlinger
  telephony.registry
  textservices
  throttle
  uimode
  updatelock
  usagestats
  usb
  vibrator
  wallpaper
  wifi
  wifip2p
  window
getevent -> toolbox The getevent tool runs on the device and provides information about input devices and a live dump of kernel input events.
Usage: getevent [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r]
[device]
    -t: show time stamps
    -n: don't print newlines
    -s: print switch states for given bits
    -S: print all switch states
    -v: verbosity mask (errs=1, dev=2, name=4, info=8, vers=16, pos. events=32, props=64)
    -d: show HID descriptor, if available
    -p: show possible events (errs, dev, name, pos. events)
    -i: show all device info and possible events
    -l: label event types and names in plain text
    -q: quiet (clear verbosity mask)
    -c: print given number of events then exit
    -r: print rate events are received
http://source.android.com/tech/input/getevent.html
getprop -> toolbox List some property of Android
hd -> toolbox To sum up each character in specified file and result the summation.
To do hd command repeatedly and to set delay interval between each execution if -r is designated.
Usage: hd [-b base] [-c count] [-r delay] file
id -> toolbox Print uid, gid, and context
ifconfig -> toolbox TCP/IP command. Assign an address to a network interface and/or configure network interface parameters. ifconfig is typically used at boot time to define the network address of each interface on a machine.
iftop -> toolbox Show the packet flow for each network interface
Usage: iftop [ -r repeats] [ -d delay ]
input Send string or key event to device
usage: input [text|keyevent]
       input text
       input keyevent
insmod -> toolbox Load a module into the kernel at runtime. The module cannot be used after reboot.
Usage: insmod
ioctl -> toolbox IO Control Command between Up and lower layer.
ioctl [-l ] [-a ] [-rdh]
  -l    Length of io buffer
  -a   Size of each argument (1-8)
  -r            Open device in read only mode
  -d            Direct argument (no iobuffer)
  -h            Print help
ionice -> toolbox Configure the Process.
Usage: ionice [none|rt|be|idle] [prio]
kill -> toolbox Kill the process
usage:  kill [-s signame | -signum | -signame] { job | pid | pgrp }
        kill -l [exit_status ...]
ln -> toolbox Create pseudonyms (links) for files, allowing them to be accessed by different names.
ln [-s]
log -> toolbox Display specified log information.
USAGE: log [-p priorityChar] [-t tag] message
        priorityChar should be one of:
                v,d,i,w,e
logcat Real time Log for all application running on Android System.
options include:
  -s              Set default filter to silent.
                  Like specifying filterspec '*:s'
  -f    Log to file. Default to stdout
  -r []   Rotate log every kbytes. (16 if unspecified). Requires -f
  -n       Sets max number of rotated logs to , default 4
  -v      Sets the log print format, where is one of:

                  brief process tag thread raw time threadtime long

  -c              clear (flush) the entire log and exit
  -d              dump the log and then exit (don't block)
  -t       print only the most recent lines (implies -d)
  -g              get the size of the log's ring buffer and exit
  -b      Request alternate ring buffer, 'main', 'system', 'radio'
                  or 'events'. Multiple -b parameters are allowed and the
                  results are interleaved. The default is -b main -b system.
  -B              output the log in binary
filterspecs are a series of
  [:priority]

where is a log component tag (or * for all) and priority is:
  V    Verbose
  D    Debug
  I    Info
  W    Warn
  E    Error
  F    Fatal
  S    Silent (supress all output)

'*' means '*:d' and by itself means :v

If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.
If no filterspec is found, filter defaults to '*:I'

If not specified with -v, format is set from ANDROID_PRINTF_LOG
or defaults to "brief"
ls -> toolbox List the file and directory at current or specified path.
Usage: ls -l: LIST_LONG; break;
-n:LIST_LONG | LIST_LONG_NUMERIC; break;
-s: LIST_SIZE; break;
-R:LIST_RECURSIVE; break;
-d: LIST_DIRECTORIES; break;
-Z: LIST_MACLABEL; break;
-a: LIST_ALL; break;
-F: LIST_CLASSIFY; break;
lsmod -> toolbox List the module in Android device.
lsof -> toolbox List information in /Proc folder which contains all the process information.
md5 -> toolbox MD5 encription tool
mkdir -> toolbox Create a folder.
monkey A automation stress test tool which generates random event for Android device.
mount -> toolbox Mount a file structure.
Usage: mount [-r] [-w] [-o options] [-t type] device directory
mv -> toolbox Remove a file.
USAGE: mv
nandread -> toolbox nandread [-d ] [-f file] [-s sparesize] [-vh]
  -d    Read from
  -f   Write to
  -s   Number of spare bytes in file (default 64)
  -R         Raw mode
  -S Start offset (default 0)
  -L    Length (default 0)
  -v         Print info
  -h         Print help
netcfg Configure network interface
usage: netcfg [ {dhcp|up|down}]
netstat -> toolbox Print net state
newfs_msdos -> toolbox New a file System with specified format
usage: newfs_msdos [ -options ] special [disktype]
where the options are:
        -@ create file system at specified offset
        -B get bootstrap from file
        -C create image file with specified size
        -F FAT type (12, 16, or 32)
        -I volume ID
        -L volume label
        -N don't create file system: just print out parameters
        -O OEM string
        -S bytes/sector
        -a sectors/FAT
        -b block size
        -c sectors/cluster
        -e root directory entries
        -f standard format
        -h drive heads
        -i file system info sector
        -k backup boot sector
        -m media descriptor
        -n number of FATs
        -o hidden sectors
        -r reserved sectors
        -s file system size (sectors)
        -u sectors/track
ping Check if the specified host address is online.
pm Package Manager for running Dalvik Class file.
printenv -> toolbox Print Environment Variables and their Values for Android Device
ps -> toolbox Print the running process with its state.
Usage: ps [options]
    -t   Show threads
   -x   Show time
   -Z   Show MAC Label
   -P   Show Policy
   -p   Show Priority
   -c   Show CPU
reboot -> toolbox Reboot Android Device
renice -> toolbox Change the priority of a process.
USAGE: renice [[-r] priority pids ...] [-g pid]
rm -> toolbox Remove a file or folder.
Usage: rm file_name or rm -r folder_name  
rmdir -> toolbox Remove the folder.
Usage: rmdir
rmmod -> toolbox Remove a module
usage: rmmod
route -> toolbox Add or Remove route
Ex: route add -net 192.168.1.2 netmask 255.255.255.0 gw 192.168.1.1
screencap Output Android screen
usage: screencap [-hp] [FILENAME]
   -h: this message
   -p: save the file as a png.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.
screenshot Output Android screen
usage: screenshot [-s soundfile] filename.png
   -s: play a sound effect to signal success
   -i: autoincrement to avoid overwriting filename.png
sendevent -> toolbox Send a event trigger to specified device with type, code, and value. E.g. Touch, or Key.
Usage: sendevent [device] [type] [code] [value].
service Service operation
Usage: service [-h|-?]
       service list
       service check SERVICE
       service call SERVICE CODE [i32 INT | s16 STR] ...
Options:
   i32: Write the integer INT into the send parcel.
   s16: Write the UTF-16 string STR into the send parcel.
setconsole -> toolbox setconsole [-d ] [-v ] [-gtncpoh]
  -d    Use instead of /dev/tty0
  -v     Switch to virtual console
  -g         Switch to graphics mode
  -t         Switch to text mode
  -n         Create and switch to new virtual console
  -c         Close unused virtual consoles
  -p         Print new virtual console
  -o         Print old virtual console
  -h         Print help
setprop -> toolbox Set the Android property.
Usage: setprop
sh -> mksh Execute a shell script.
sleep -> toolbox Interval of next action/command (seconds)
start -> toolbox Start a specified service
stop -> toolbox Stop a specified service
sync -> toolbox Copy host->device only if changed. adb sync is a tool which may be used to copy files from the computer to the device if the files has been changed. By default the command will synchronize /data and /system unless one option is specified. For the command to operate properly a system variable must be created and defined. ANDROID_PRODUCT_OUT must designate the full actual path to the directory containing a file structure with system and/or data subfolders containing the files and folders changed.
Usage: sync [ ]
toolbox Check if the specified command existed.
Usage: toolbox command_name
top -> toolbox Display usage of thread or process.
Usage: top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ]
    -m num  Maximum number of processes to display.
    -n num  Updates to show before exiting.
    -d num  Seconds to wait between updates.
    -s col  Column to sort by (cpu,vss,rss,thr).
    -t      Show threads instead of processes.
    -h      Display this help screen.
umount -> toolbox Unmount the device
Usage: umount device_path
uptime -> toolbox The up time since last boot. The information includes up, idle, and sleep time.
vmstat -> toolbox Virtual Meomory Statistics
Usage: vmstat [ -h ] [ -n iterations ] [ -d delay ] [ -r header_repeat ]
    -n iterations     How many rows of data to print.
    -d delay          How long to sleep between rows.
    -r header_repeat  How many rows to print before repeating
                      the header.  Zero means never repeat.
    -h                Displays this help screen.
vold Manage the device on Android. The function is similar with udev in Linux.
watchprops -> toolbox Monitor the change of property and list them. The properties can be viewed by executing getprop and set by executing setprop.
wipe -> toolbox Erase the system or data
Usage: wipe
   system means '/system'
   data means '/data'
wpa_supplicant Configure WLAN
usage:
  wpa_supplicant [-BddhKLqqstuvW] [-P] [-g] \
        -i -c [-C] [-D] [-p] \
        [-b] [-f] [-e] \
        [-o] [-O] \
        [-N -i -c [-C] [-D] \
        [-p] [-b] ...]

drivers:
  nl80211 = Linux nl80211/cfg80211
options:
  -b = optional bridge interface name
  -B = run daemon in the background
  -c = Configuration file
  -C = ctrl_interface parameter (only used if -c is not)
  -i = interface name
  -d = increase debugging verbosity (-dd even more)
  -D = driver name (can be multiple drivers: nl80211,wext)
  -e = entropy file
  -g = global ctrl_interface
  -K = include keys (passwords, etc.) in debug output
  -t = include timestamp in debug messages
  -h = show this help text
  -L = show license (GPL and BSD)
  -o = override driver parameter for new interfaces
  -O = override ctrl_interface parameter for new interfaces
  -p = driver parameters
  -P = PID file
  -q = decrease debugging verbosity (-qq even less)
  -v = show version
  -W = wait for a control interface monitor before starting
  -N = start describing new interface
example:
  wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf

10 則留言: