Shell CentOS – Difference Between -o comm and -o command in ps

centosshell

On CentOS 7.0.1406 I get differing output when running

ps -A -o pid,command | grep [r]esque

than when I run

ps -A -o pid,comm | grep [r]esque

The latter returns nothing; the former what I would expect. I was under the impression that comm was an alias for command. Could someone please explain the difference?

Best Answer

They are not aliases. Command outputs the full command and comm only the command name, so it is possible that the outputs are different. It all depends on what you want to extract the grep command.

An example:

$ ps -A -o pid,command | grep 9600
376 /sbin/agetty --keep-baud 115200 38400 9600 ttyS0 vt220

and the output for the following is empty:

ps -A -o pid,comm | grep 9600

The string 9600 is part of the complete command but the command name.

command, and cmd are aliases to args, with prints the command with all its arguments as string. comm is a different sorting code that prints only the executable name. Manpage snippet:

   args      COMMAND command with all its arguments as a string.

   cmd       CMD    see args. (alias args, command).

   comm      COMMAND command name (only the executable name).

   command   COMMAND see args. (alias args, cmd).