Ubuntu – Output only the column under COMMAND of `ps` command in terminal

command lineps

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

 ps -o command  

To list all system processes

 ps -e -o command

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:

command, args, and cmd all give full command. In fact man page states command and cmd are aliases for args , with the - flags included. The comm gives the name of the exacutable only. Aliases to that are ucmd and ucomm. I misread about AIX options, those can be actually specified with printf-like format, %a for args, %c for comm

Refer to man ps for more info on usage and available format options

Programmatic approach would be a bit redundant , since ps already provides us with the formatting options, but it can be done with awk, which is much useful when dealing with columnized output.

ps aux | awk '{ for(i=1;i<=NF;i++) {if ( i >= 11 ) printf $i" "}; printf "\n" }'

Note however, that this code breaks if username contains whitespace, e.g. john doe. This can be amended with adding gsub function that will elimiate your username from the ps 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 with ps