2

When I run pgrep vim | xargs ps, it prints

  PID   TT  STAT      TIME COMMAND
91234 s001  S+     0:03.14 vi user.py
93868 s005  S+     0:01.55 vi video.py

Yet when I run

pgrep vim | xargs ps -o command

it prints

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

How can I print only

user.py
video.py
4

2 回答 2

1
pgrep vim | xargs ps | sed 1d | perl -lane 'print $F[5]'
于 2013-09-15T22:06:58.987 回答
0
pgrep vim | while read pid; do ps -p $pid -o command; done|grep -v "^COMMAND"
于 2014-10-20T19:35:35.923 回答