当我运行pgrep vim | xargs ps
时,会打印
PID TT STAT TIME COMMAND
91234 s001 S+ 0:03.14 vi user.py
93868 s005 S+ 0:01.55 vi video.py
但是当我跑步时
pgrep vim | xargs ps -o command
打印
COMMAND
-bash
tmux -2
-bash
vi user.py
-bash
-bash
vi video.py
(pgrep)
xargs ps -o command
-bash
-bash
-bash
-bash
-bash
sqlite3 spot.db
-bash
-bash
python app.py
/usr/bin/python app.py
-bash
/usr/bin/man lsof
sh -c (cd '/usr/share/man' && (echo ".ll 9.8i"; echo ".nr LL 9.8i"; /bin/cat '/usr/share/man/man8/lsof.8') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | (/usr/bin/less -is || true))
sh -c (cd '/usr/share/man' && (echo ".ll 9.8i"; echo ".nr LL 9.8i"; /bin/cat '/usr/share/man/man8/lsof.8') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | (/usr/bin/less -is || true))
/usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c
sh -c (cd '/usr/share/man' && (echo ".ll 9.8i"; echo ".nr LL 9.8i"; /bin/cat '/usr/share/man/man8/lsof.8') | /usr/bin/tbl | /usr/bin/groff -Wall -mtty-char -Tascii -mandoc -c | (/usr/bin/less -is || true))
/usr/bin/less -is
grotty
我如何才能打印
user.py
video.py
答案 0 :(得分:1)
pgrep vim | xargs ps | sed 1d | perl -lane 'print $F[5]'
答案 1 :(得分:0)
pgrep vim | while read pid; do ps -p $pid -o command; done|grep -v "^COMMAND"