Skip to content
shellhacks.dev
Linux

List Linux Processes with a Custom ps Output Format

Choose the columns of ps with -o. The comm column is cut at 15 characters while args shows the full command line, and name= drops the header.

1 min read
Summarize in AI

The default ps listing has columns you do not need and lacks the one you do, such as parent PID or memory.

Shell
cp /bin/sleep /tmp/a_very_long_process_name
/tmp/a_very_long_process_name 300 &
ps -o stat,comm,args -p $!
ps -o comm= -o args= -p $!
ps -o comm=NAME -o etimes=SECONDS -p $!
kill $!
Text
STAT COMMAND         COMMAND
S    a_very_long_pro /tmp/a_very_long_process_name 300
a_very_long_pro /tmp/a_very_long_process_name 300
NAME            SECONDS
a_very_long_pro       0

-o takes a list of format keywords, from pid, ppid and %mem to etimes, and -o name= replaces a header with your own text or, when empty, removes it, which is the form for scripts. The comm column is the kernel's process name, limited to 15 characters, while args is the full command line, so the first line shows the same process named two ways. Both are among the ps format specifiers. cmd is a synonym for args.

These are the Linux procps options. BSD and macOS ps take a different syntax, where -o still works but -e and etimes may not. A column is as wide as its widest entry, and a long args is cut to the terminal width unless output goes to a pipe or ww is added.

Share

More snippets

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.