ps -el |grep systemd
4 S 0 1 0 0 80 0 - 7233 - ? 00:00:00 systemd
如何获得以下输出格式?
ps -el |grep systemd
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 1 0 0 80 0 - 7233 - ? 00:00:00 systemd
答案1
由于ps
可以搜索命令名称:
$ ps -lC systemd
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 1 0 1 80 0 - 33838 ep_pol ? 00:00:01 systemd
4 S 1000 733 1 0 80 0 - 15347 ep_pol ? 00:00:00 systemd
或者使用pgrep
搜索:
$ ps -l -p $(pgrep -d, systemd)
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 1 0 0 80 0 - 33838 ep_pol ? 00:00:01 systemd
4 S 0 242 1 0 80 0 - 60300 ep_pol ? 00:00:00 systemd-journal
4 S 0 275 1 0 80 0 - 11267 ep_pol ? 00:00:00 systemd-udevd
4 S 0 546 1 0 80 0 - 11228 ep_pol ? 00:00:00 systemd-logind
4 S 1000 733 1 0 80 0 - 15347 ep_pol ? 00:00:00 systemd
答案2
您可以尝试对 grep 使用-e
标志,让它在第一行中查找额外的模式,如下所示:
ps -el | grep -e systemd -e "TIME CMD"