关于shell:mac-上PS命令使用指北

32次阅读

共计 2908 个字符,预计需要花费 8 分钟才能阅读完成。

失常的 ps 命令是打印进去 PID TTY TIME CMD 四个字段

  PID TTY           TIME CMD
 5131 ttys000    0:00.20 -zsh
14330 ttys000    0:00.46 ios_webkit_debug_proxy -f chrome-devtools://devtools/b
60457 ttys001    0:00.31 -zsh
 7097 ttys002    0:00.14 -zsh
88776 ttys003    0:00.22 -zsh
 4748 ttys004    0:07.38 /Library/Frameworks/Python.framework/Versions/3.8/Reso
76131 ttys004    0:00.59 -zsh
16212 ttys005    0:00.24 -zsh
42452 ttys005    0:03.67 /usr/bin/java -jar UICrawler-2.0.jar -u d4917fbadf4b71
28402 ttys006    0:00.28 -zsh
43381 ttys009    0:00.15 -zsh

看到挺诡异的没,CMD 内容过长被截断了,UICrawler 这一行自身很长, 如何显示出残缺的门路呢,ps -f 打印出残缺信息 ( 起初发现这个把终端宽度拖宽一点就能够显示了, 他只是一行显示不下不回换行, 害我弄良久, 垃圾,ps - f 默认应该是能够多行显示)

 ps -f 
  UID   PID  PPID   C STIME   TTY           TIME CMD
  501  5131  5130   0 10:02 上午 ttys000    0:00.20 -zsh
  501 14330  5131   0 10:17 上午 ttys000    0:00.48 ios_webkit_debug_proxy -f chrome-devtools://devtools/bundled/inspector.html
  501 60457 60456   0 四 10 上午 ttys001    0:00.31 -zsh
  501 88776 88775   0 12:27 下午 ttys003    0:00.22 -zsh
  501  4748 76131   0 10:01 上午 ttys004    0:07.53 /Library/Frameworks/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python ocrServer.py
  501 76131 76130   0  4:36 下午 ttys004    0:00.59 -zsh
  501 16212 16211   0 10:19 上午 ttys005    0:00.24 -zsh
  501 47021 16212   0  2:30 下午 ttys005    0:04.07 /usr/bin/java -jar UICrawler-2.0.jar -u d4917fbadf4b71db3c9b3a835f100099b0432442 -s 127.0.0.1 -t 4723 -f config_ios.yml -b com.tencent.weread -o out_file -log
  501 48459 47021   0  2:33 下午 ttys005    0:00.01 /usr/local/bin/idevicescreenshot -u d4917fbadf4b71db3c9b3a835f100099b0432442 out_file/del.png
  501 43381 43380   0  2:24 下午 ttys009    0:00.18 -zsh

内容是齐全了,怎么能力把除了 CMD 字段的其余内容去掉 ps -fo command?

ijm@172-10-20-5 ~ % ps -fo command 
  UID   PID  PPID   C STIME   TTY           TIME CMD              COMMAND
  501  5131  5130   0 10:02 上午 ttys000    0:00.20 -zsh             -zsh
  501 14330  5131   0 10:17 上午 ttys000    0:00.49 ios_webkit_debug ios_webkit_debug_proxy -f chrome-devtools://devtools/bundled/inspector.html
  501 60457 60456   0 四 10 上午 ttys001    0:00.31 -zsh             -zsh
  501 52840 52839   0  2:40 下午 ttys002    0:00.15 -zsh             -zsh
  501 88776 88775   0 12:27 下午 ttys003    0:00.22 -zsh             -zsh
  501  4748 76131   0 10:01 上午 ttys004    0:07.66 /Library/Framewo /Library/Frameworks/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python ocrServer.py
  501 76131 76130   0  4:36 下午 ttys004    0:00.59 -zsh             -zsh
  501 16212 16211   0 10:19 上午 ttys005    0:00.24 -zsh             -zsh
  501 50840 16212   0  2:38 下午 ttys005    0:03.91 /usr/bin/java -j /usr/bin/java -jar UICrawler-2.0.jar -u d4917fbadf4b71db3c9b3a835f100099b0432442 -s 127.0.0.1 -t 4723 -f config_ios.yml -b com.tencent.weread -o out_file -log

不行啊 - f 会把所有的字段显示进去, 起初搜寻 ps -o command

ijm@172-10-20-5 ~ % ps -o command
COMMAND
-zsh
ios_webkit_debug_proxy -f chrome-devtools://devtools/bundled/inspector.html
-zsh
-zsh
-zsh
/Library/Frameworks/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python ocrServer.py
-zsh
-zsh
/usr/bin/java -jar UICrawler-2.0.jar -u d4917fbadf4b71db3c9b3a835f100099b0432442 -s 127.0.0.1 -t 4723 -f config_ios.yml -b com.tencent.weread -o out_file -log

这里只会展现终端启动的一些过程, 没有终端的过程是显示不进去. 命令 - A 或 - e 解决这个问题 ps -Ao command 或 ps -eo command
最终命令我要搜寻 UICrawler 过程:
ps -Ao command |grep UICrawler

ijm@172-10-20-5 ~ % ps -Ao command |grep UICrawler
grep UICrawler
/usr/bin/java -jar UICrawler-2.0.jar -u d4917fbadf4b71db3c9b3a835f100099b0432442 -s 127.0.0.1 -t 4723 -f config_ios.yml -b com.tencent.weread -o out_file -log

正文完
 0