0

The question is basic, How to get output of ps with headers in Linux.

Linux details:

PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"

I can get it with ps -ef | { head -1; grep query; }, but that is lot of text. When looking at docs of ps using man ps, I can see there is one option --headers, but using that also does not give headers:

>~$ ps aux --headers | grep grep
user  24082  0.0  0.0   6656   628 pts/0    S+   12:59   0:00 grep grep

Also tried option h with the command:

~$ ps auxh  | grep grep
user  25982  0.0  0.0   6656   624 pts/0    S+   13:14   0:00 grep grep
Saurabh
  • 123
  • 1
  • 8

1 Answers1

5
  1. I am not sure headers is needed.
  2. the headers are printed, but are filtred out by grep.

awk solution

ps aux --headers| awk 'NR==1 || /awk/ '
  • NR==1 keep first line
  • || or
  • /awk/ line with awk

egrep solution

ps aux | egrep '^USER|grep' 
  • either ^USER USER string at start of line
  • or grep string

ps solution

If string match a program, you can use -C option (along with needed fields)

ps -C sshd -o stime,etime,args
Archemar
  • 1,369
  • 11
  • 19