Is there any way to get pgrep
to give me all the info about each process that ps
does? I know I can pipe ps
through grep
but that's a lot of typing and it also gives me the grep
process itself which I don't want.
Is there any way to get pgrep
to give me all the info about each process that ps
does? I know I can pipe ps
through grep
but that's a lot of typing and it also gives me the grep
process itself which I don't want.
pgrep
's output options are pretty limited. You will almost certainly need to send it back throughps
to get the important information out. You could automate this by using a bash function in your~/.bashrc
.Then call the command with.
Combine
pgrep
withps
usingxargs
!For example try
to get a full process list of
user
. Option-u user
limitspgrep
to the user given (as a number or name) while theps
options-f -p
request a full format listing for the selected PID.It's nice that you keep the first line with the column names.
grep
always drops the column names.The following only gives you PID + full command-line. For "all the info
ps
does", see other answers...Most linuxes use procps-ng. Since 3.3.4 (released in 2012),
pgrep -a
(--list-full
) shows the full command line.Note: By default pgrep only matches the pattern you give against the executable name. If you want to match against the full command line (as grepping ps does), add the
-f
(--full
) option.In older versions (including the original procps project),
-l
option showed info but it's behavior varied:pgrep -fl
matched the pattern against full command line and showed the full command line.pgrep -l
alone matched only executable name and showed only executable name.If you don't want full match, you couldn't see the full command line :-( [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=526355#15]
Not sure what code *BSD use but their man page documents the old
-fl
behavior.Unfortunately you can't even use
-fl
portably - in recent procps-ng,-f
(--list-name
) always prints only the executable name.Linux grep
For the GNU version of
pgrep
long + fuzzy output is achieved with-af
and the string must be case-sensitive (i.e. there is no option for case-insensitivity).Man page:
MacOS/BSD grep
On MacOS/BSD
-l
(long output) in combination with-f
(match against full argument lists) will display the complete command (-i
adds case-insensitivity):man page:
Use the -v option to grep - it returns everything BUT the requested pattern.
I know it is an old topic. However, It was useful to me, and I would like to share what I did that worked. It is pretty straightforward for beginner (like me) and may help others:
Note that the column "CMD" was also showed, but the question of this thread was to show the command, and not only the command. Anyway, I am trying to remove that column and will update my post with the command too.
Note: The arguments "--no-headers and -o command" isolated the output only to the command. And I could remove the awk print.
I don't think there is, the most information you can get is the name and process id by using the -l option to pgrep.
ps supports all sorts of formatting options, so I would just make an alias for what you want to save the typing. A simple way to exclude the grep process from the output us to include an additional pipe to
grep -v grep
to exclude any grep processes.In order to eliminate the
grep
process, you can use brackets as part of your pattern:You can do this with
ps
andpgrep
:This will help you I guess:
ps auxww