分享

adb shell 常用命令(一)

 昵称3884271 2015-12-01

 adb shell 里面有许多有用的命令可以帮助我们对android模拟器或设备进行操作

首先进入adb shell

C:\Users\xuxu>adb shell

root@xumin:/ #


(一)基本的linux命令

1.ls

列出当前目录下的文件夹和文件,可以用ls -l或直接ll列出详细内容

root@xumin:/ # ll

ll

drwxr-xr-x root     root              1970-01-28 13:48 acct

drwxrwx--- system   cache             1970-01-28 08:03 cache

-rwxr-x--- root     root       268456 1970-01-01 08:00 charger

dr-x------ root     root              1970-01-28 13:48 config

lrwxrwxrwx root     root              1970-01-28 13:48 d -> /sys/kernel/debug

drwxrwx--x system   system            2014-06-08 12:25 data


2.pwd

打印出当前所在的目录路径,在写脚本的时候会有用

root@xumin:/system/app # pwd

pwd

/system/app


3.cd

切换目录

"cd -" 切换到上次目录

"cd .." 切换到上级目录

"cd ../.."切换到上级的上级目录

目录名较长时建议使用通配符"*",如cd到system目录:

root@xumin:/ # cd sy*m

cd sy*m

root@xumin:/system #


4.cp

复制文件,如复制当前目录下的xumin-song.mp3到当前目录下的tmp目录下:

root@xumin:/storage/sdcard0 # cp xumin-song.mp3 ./tmp

cp xumin-song.mp3 ./tmp

root@xumin:/storage/sdcard0 # cd tmp

cd tmp

root@xumin:/storage/sdcard0/tmp # ls

ls

xumin-song.mp3


5.mv

移动文件或者文件夹,重命名。如重命名当前目录下的xumin-song.mp3为music.mp3:

root@xumin:/storage/sdcard0/tmp # ls

ls

xumin-song.mp3

root@xumin:/storage/sdcard0/tmp # mv *.mp3 music.mp3

mv *.mp3 music.mp3

root@xumin:/storage/sdcard0/tmp # ls

ls

music.mp3


5.chmod

修改文件或文件夹的权限,写shell脚本的时候需要用到

r:可读,4;w:可写, 2;x:可执行,1

7:4+2+1,可读可写可执行

6:4+2+0,可读可写

5:4+0+1,可读可执行


chmod filename 755


6.cat,more

显示文件内容

cat filename

more file name


7.rm,rmdir

rm,***文件

rmdir,***目录


8.df

显示磁盘空间大小

root@xumin:/ # df

df

Filesystem               Size     Used     Free   Blksize

/dev                   917.1M    64.0K   917.0M   4096

/mnt/secure            917.1M     0.0K   917.1M   4096

/mnt/asec              917.1M     0.0K   917.1M   4096

/mnt/obb               917.1M     0.0K   917.1M   4096

/system               1006.7M   634.9M   371.8M   4096

/data                    2.0G   251.3M     1.7G   4096

/cache                 377.8M     6.0M   371.8M   4096

/persist                 4.9M     4.1M   844.0K   4096

/firmware               64.0M    51.9M    12.0M   16384

/mnt/shell/emulated      2.0G   251.3M     1.7G   4096

/storage/emulated/legacy     2.0G   251.3M     1.7G   4096

/storage/sdcard0        10.2G   155.8M    10.1G   4096

/mnt/secure/asec        10.2G   155.8M    10.1G   4096


9.du

显示目录空间大小


10.grep

查找字符串


11.ps

显示系统瞬时进程状态

root@xumin:/storage/sdcard0 # ps

ps

USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME

root      1     0     668    536   c02662d8 00018288 S /init

root      2     0     0      0     c01af750 00000000 S kthreadd

root      3     2     0      0     c0198b5c 00000000 S ksoftirqd/0

root      6     2     0      0     c0179518 00000000 D kworker/u:0

root      7     2     0      0     c0176b58 00000000 D kworker/u:0H

root      8     2     0      0     c01e6448 00000000 S migration/0

root      9     2     0      0     c01f0624 00000000 S watchdog/0

root      25    2     0      0     c01aafb8 00000000 S khelper

root      26    2     0      0     c01aafb8 00000000 S netns


使用管道结合grep可以查看具体进程的状态:

root@xumin:/ # ps | grep com.android.launcher

ps | grep com.aurora.launcher

system    32078 31454 943108 71308 ffffffff 400ec5b0 S com.android.launcher


12.top

动态的显示进程状态

动态的显示com.android.launcher进程状态:

top | grep com.android.launcher

32078  0   0% S    19 943108K  71308K  fg system   com.android.launcher

32078  0   0% S    19 943108K  71308K  fg system   com.android.launcher

32078  0   0% S    19 943108K  71308K  fg system   com.android.launcher

32078  0   0% S    19 943108K  71308K  fg system   com.android.launcher

32078  0   0% S    19 943108K  71308K  fg system   com.android.launcher

32078  0   0% S    19 943108K  71308K  fg system   com.android.launcher


13.kill

杀死进程

kill pid

杀死com.android.launcher


root@xumin:/ # ps | grep com.android.launcher

ps | grep com.android.launcher

system    32078 31454 943108 71308 ffffffff 400ec5b0 S com.android.launcher

root@xumin:/ # kill 32078


14.touch

创建文件

root@xumin:/storage/sdcard0/tmp # touch test.txt

touch test.txt

root@xumin:/storage/sdcard0/tmp # ls

ls

music.mp3

music_backup

test.txt


15.mkdir

创建目录

root@xumin:/storage/sdcard0/tmp # mkdir newdir

mkdir newdir

root@xumin:/storage/sdcard0/tmp # ls

ls

music.mp3

music_backup

newdir

test.txt


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多