I know that we can easily find the following:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
of all the running processes by using the command:
sudo ps aux
My, question is that, is it possible to show the output of only the column under COMMAND
and nothing else?
Best Answer
Use
-o
flag.To list only your own processes
To list all system processes
This is not the only way to list commands, they can either be printed with command line flags, or as executable only (which is what
command
option does).From my comment bellow the answer:
Refer to
man ps
for more info on usage and available format optionsProgrammatic approach would be a bit redundant , since
ps
already provides us with the formatting options, but it can be done withawk
, which is much useful when dealing with columnized output.Note however, that this code breaks if username contains whitespace, e.g.
john doe
. This can be amended with addinggsub
function that will elimiate your username from theps
list. However, if there is multiple users logged into system, that may be difficult to errase all of the usernames from the output. Thus, you can see that-o
flag is much more preferred.Side note,
sudo
is not necessary to for listing all processes withps