Android常用的Linux命令

当用adb shell进入Android系统后,即可输入linux命令,下面就对一些Andriod常用的linux命令进行汇总!

1.目录与文件

pwd

查看当前完整路径

natrium:/sdcard/MOVIES $ pwd
/sdcard/MOVIES

ls

列出当前目录的所有文件

natrium:/sdcard/MOVIES $ ls
demo.sh  dync.mp4  frozen2.mov  shalala.mp3  shupin.mp4  static.mp4
ls -alh

以便于阅读的字节单位查看文件详细列表,包括隐藏文件或目录

  • a 显示隐藏文件
  • l 以行显示
  • h 文件大小单位自动转换显示
natrium:/sdcard/MOVIES $ ls -alh
total 92M
drwxrwx--x   2 root sdcard_rw 4.0K 2019-10-24 21:29 .  //隐藏目录,上一层
drwxrwx--x 245 root sdcard_rw 8.0K 2019-10-24 20:38 ..  //隐藏目录,上上一层
-rw-rw----   1 root sdcard_rw   26 2019-10-23 08:17 demo.sh
-rw-rw----   1 root sdcard_rw  78M 2019-06-29 13:29 dync.mp4
-rw-rw----   1 root sdcard_rw  89M 2019-07-05 16:01 frozen2.mov
-rw-rw----   1 root sdcard_rw 3.3M 2019-07-02 20:00 shalala.mp3
-rw-rw----   1 root sdcard_rw  12M 2019-07-07 17:35 shupin.mp4
-rw-rw----   1 root sdcard_rw 1.1M 2019-07-02 19:51 static.mp4

cd

切换路径(change dirtory)

natrium:/sdcard/MOVIES $ cd /sdcard/Android
natrium:/sdcard/Android $ pwd
/sdcard/Android
  • cd . 当前目录
  • cd ..回到上级目录

mkdir

创建一个单层新目录

natrium:/sdcard/MOVIES $ mkdir testdir
natrium:/sdcard/MOVIES $ ls
demo.sh  demo2.sh  dync.mp4  frozen2.mov  shalala.mp3  shupin.mp4  static.mp4  testdir
mkdir -p

创建多级目录

natrium:/sdcard/MOVIES $ mkdir -p ./multidir/testdir2
natrium:/sdcard/MOVIES $ ls
demo.sh  demo2.sh  dync.mp4  frozen2.mov  multidir  shalala.mp3  shupin.mp4  static.mp4  testdir
natrium:/sdcard/MOVIES $ cd multidir/   //子级目录被创建
natrium:/sdcard/MOVIES/multidir $ ls
testdir2  //第二层目录被创建

cp

复制文件或目录(copy)

natrium:/sdcard/MOVIES $ cp demo.sh ./testdir/democp.sh  //将demo.sh复制到另一目录中并重新命名为demo.cp.sh
natrium:/sdcard/MOVIES $ cd testdir
natrium:/sdcard/MOVIES/testdir $ ls
democp.sh

rm

删除文件(remove)

natrium:/sdcard/MOVIES/testdir $ ls
democp.sh
natrium:/sdcard/MOVIES/testdir $ rm democp.sh
natrium:/sdcard/MOVIES/testdir $ ls
natrium:/sdcard/MOVIES/testdir $
rm -r

删除目录

natrium:/sdcard/MOVIES $ rm -r testdir/
natrium:/sdcard/MOVIES $ ls
demo.sh  dync.mp4  frozen2.mov  multidir  shalala.mp3  shupin.mp4  static.mp4
natrium:/sdcard/MOVIES $

2.文件内容输入与查看

vim

vim helloworld.txt

打开编辑器并创建一个新文件helloworld.txt,由于手机未带vim编辑器故无示例。

touch

直接生成一个新文件

natrium:/sdcard/MOVIES/multidir $ touch hello.txt
natrium:/sdcard/MOVIES/multidir $ ls
hello.txt  testdir2

echo >

向文件中输入内容,如无文件则新建。

natrium:/sdcard/MOVIES/multidir $ echo "Hello World" > helloecho.txt
natrium:/sdcard/MOVIES/multidir $ ls
hello.txt  helloecho.txt  testdir2
  • >单个大于号会直接覆盖原有文件内容
  • >>两个大于号会把内容追加到文件末尾,自带换行。

cat

查看文件内容

natrium:/sdcard/MOVIES/multidir $ echo "I am Second Line" >> helloecho.txt
natrium:/sdcard/MOVIES/multidir $  cat helloecho.txt
Hello World
I am Second Line

more

查看文件内容的另一种方式

natrium:/sdcard/MOVIES/multidir $ more helloecho.txt
Hello World
I am Second Line

find

查找特定文件

natrium:/sdcard/MOVIES $ find . -name "*txt"  //.表示在当前目录下查找,后缀为txt的所有文件
./multidir/hello.txt
./multidir/helloecho.txt

3.系统信息查看

ps -ef

查看所有进程

natrium:/sdcard/MOVIES/multidir $ ps -ef
UID            PID  PPID C STIME TTY          TIME CMD
root             1     0 0 07:25 ?        00:03:49 init
root             2     0 0 07:25 ?        00:00:08 [kthreadd]
root             3     2 1 07:25 ?        03:04:50 [ksoftirqd/0]
root             7     2 1 07:25 ?        03:26:20 [rcu_preempt]
root             8     2 0 07:25 ?        00:09:37 [rcu_sched]
root             9     2 0 07:25 ?        00:00:00 [rcu_bh]
root            10     2 0 07:25 ?        00:14:49 [migration/0]
root            11     2 0 07:25 ?        00:13:00 [migration/1]
root            12     2 0 07:25 ?        01:40:40 [ksoftirqd/1]
root            15     2 0 07:25 ?        00:28:58 [migration/2]
root            16     2 0 07:25 ?        00:41:20 [ksoftirqd/2]
root            19     2 0 07:25 ?        00:29:56 [migration/3]
root            20     2 0 07:25 ?        00:27:59 [ksoftirqd/3]
root            23     2 0 07:25 ?        00:00:00 [khelper]
root            24     2 0 07:25 ?        00:00:00 [netns]
  • kill pid可直接干掉进程

df -h

查看存储空间大小

natrium:/sdcard/MOVIES/multidir $ clear  //清屏命令
natrium:/sdcard/MOVIES/multidir $ df -h
Filesystem       Size  Used Avail Use% Mounted on
rootfs           2.6G  6.2M  2.6G   1% /
tmpfs            2.7G  732K  2.7G   1% /dev
/dev/block/dm-0  2.8G  2.5G  288M  91% /system
tmpfs            2.7G     0  2.7G   0% /mnt
none             2.7G     0  2.7G   0% /sys/fs/cgroup
/dev/block/sde38 806M  336M  454M  43% /cust
/dev/block/sda12  27M  1.1M   26M   5% /persist
/dev/block/sda14 248M  2.6M  240M   2% /cache
/dev/block/sde32  12M  4.1M  7.3M  36% /dsp
/dev/block/sde35 192M   98M   94M  51% /firmware
/dev/block/sde26 1.0G  112K  1.0G   1% /bt_firmware
/dev/block/dm-1  112G   82G   30G  74% /data
/data/media      112G   82G   30G  74% /storage/emulated

top

CPU运行状况监控,会不断地刷新,可以看到哪个进程占用的CPU使用率最高。

Tasks: 570 total,   2 running, 563 sleeping,   0 stopped,   1 zombie
Mem:   5846936k total,  5687416k used,   159520k free,   138676k buffers
Swap:  2621436k total,   530776k used,  2090660k free,  2439136k cached
400%cpu  13%user   1%nice  18%sys 363%idle   0%iow   3%irq   2%sirq   0%host
  PID USER         PR  NI VIRT  RES  SHR S[%CPU] %MEM     TIME+ ARGS
  545 system       20   0  88M 1.6M 996K R 11.0   0.0 472:30.15 [email protected]
 3274 u0_a128      20   0 2.5G 269M  99M S  6.3   4.7 175:27.24 com.tencent.mm
 9959 shell        20   0  10M 2.5M 1.4M R  5.0   0.0   0:05.09 top
 1358 system       18  -2 2.5G 250M 161M S  3.6   4.3 762:20.50 system_server
 5948 root         20   0    0    0    0 S  2.6   0.0   1:00.71 [kworker/u8:0]
 7258 root         20   0    0    0    0 S  2.0   0.0   0:45.61 [kworker/u8:8]
27220 root         20   0    0    0    0 S  1.6   0.0   1:49.94 [kworker/u8:11]
 4301 system       20   0  11M 1.1M 664K S  1.6   0.0 547:03.38 cnss_diag -q -f
    3 root         20   0    0    0    0 S  1.0   0.0 184:56.86 [ksoftirqd/0]
 9304 u999_a129    20   0 1.9G 153M  92M S  0.6   2.6   0:15.51 com.tencent.mobileqq
29691 u0_a129      20   0 2.0G 171M  99M S  0.6   3.0   2:28.84 com.tencent.mobileqq
 4305 root         20   0  12M 636K 516K S  0.6   0.0  66:39.22 tcpdump -i any -W 2 -C 2 -s 50 -w /data/vendor/wifi/tcp+
 2084 system       10 -10 2.6G 228M 122M S  0.6   3.9 286:54.39 com.android.systemui
   27 root         20   0    0    0    0 S  0.6   0.0  49:57.12 [dsps_smd_trans_]
 8988 root         20   0    0    0    0 S  0.3   0.0   0:16.96 [kworker/u8:3]
 8963 root         20   0    0    0    0 S  0.3   0.0   0:02.44 [kworker/0:3]
 7319 root         20   0    0    0    0 D  0.3   0.0   0:03.31 [kworker/1:1]
 6878 shell        20   0  15M 804K 676K S  0.3   0.0   0:05.59 adbd --root_seclabel=u:r:su:s0
24339 u0_a129      20   0 1.7G  50M  30M S  0.3   0.8   0:23.47 com.tencent.mobileqq:TMAssistantDownloadSDKService
  682 u0_a129      20   0 1.8G  52M  33M S  0.3   0.9  16:17.80 com.tencent.mobileqq:MSF
 3649 system       20   0 2.3G  55M  33M S  0.3   0.9 200:08.12 com.miui.securitycenter.remote
 2923 u0_a134      20   0 2.2G  39M  26M S  0.3   0.6  38:50.39 com.xiaomi.mircs
 2041 root         18  -2    0    0    0 S  0.3   0.0  57:18.37 [VosMCThread]
  951 root         20   0  66M 5.7M 1.3M S  0.3   0.1  44:05.15 netd
  905 root          0 -20 113M 1.5M 872K S  0.3   0.0 105:43.38 thermal-engine -T
  • CTRL+C退出监控,有些手机可能没有top命令。
  • top -H可以看到线程的占用率,默认只会显示进程占用率。

ifconfig

所有网卡IP地址查看

natrium:/sdcard/MOVIES $ ifconfig
lo        Link encap:UNSPEC
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope: Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:34925 errors:0 dropped:0 overruns:0 frame:0
          TX packets:34925 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:25387298 TX bytes:25387298

dummy0    Link encap:UNSPEC
          inet6 addr:  fea0::2a4e:187e:cfac:bce6/43 Scope: Link
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:423 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 TX bytes:29610

wlan0     Link encap:UNSPEC    Driver cnss_wlan_pci
          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr:  fea0::2a4e:187e:cfac:bce6/43 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:15084721 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5698386 errors:0 dropped:45 overruns:0 carrier:0
          collisions:0 txqueuelen:3000
          RX bytes:13000922593 TX bytes:1384413271

rmnet_data0 Link encap:UNSPEC
          inet6 addr: fea0::2a4e:187e:cfac:bce6/43 Scope: Link
          UP RUNNING  MTU:1410  Metric:1
          RX packets:64382 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1686 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:65708177 TX bytes:1338265

rmnet_ipa0 Link encap:UNSPEC
          UP RUNNING  MTU:2000  Metric:1
          RX packets:1439351 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2397761 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1989700419 TX bytes:274538941

p2p0      Link encap:UNSPEC    Driver cnss_wlan_pci
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3000
          RX bytes:0 TX bytes:0

rmnet_data2 Link encap:UNSPEC
          inet6 addr:  fea0::2a4e:187e:cfac:bce6/43 Scope: Link
          inet6 addr: 309:1212:89d1:fb7a:ee1a:5c2e:7da2:a453/64 Scope: Global
          UP RUNNING  MTU:1410  Metric:1
          RX packets:31787 errors:0 dropped:0 overruns:0 frame:0
          TX packets:44274 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:21903943 TX bytes:4623936

tcpdump

网络抓包信息查看,此命令一般要用root权限才能运行。

tcpdump: Can't open netlink socket 13:Permission denied

你可能感兴趣的:(android基础)