This works on Centos 7.
Two separate ps commands.
First ps command to get the headers.
Then a semicolon.
Then the second ps command with your specific grep.
The headers used are my standard ones.
ps -eo user,pid,ppid,lstart,etime,cmd |head -1;ps -eo user,pid,ppid,lstart,etime,cmd | grep <whatever you are grepping for |grep -v grep
Let's break it down with each part on a separate line.
ps -eo user,pid,ppid,lstart,etime,cmd |head -1
;
ps -eo user,pid,ppid,lstart,etime,cmd
| grep <whatever you are grepping for>
| grep -v grep
Actual output:
[root@myserver ~]# ps -eo user,pid,ppid,lstart,etime,cmd |head -1;ps -eo user,pid,ppid,lstart,etime,cmd |grep sshd |grep -v grep
USER PID PPID STARTED ELAPSED CMD
root 4673 1 Tue May 17 09:05:14 2022 122-09:29:11 /usr/sbin/sshd -D
root 233733 4673 Tue Sep 13 15:12:12 2022 3-03:22:13 sshd: kbanyas [priv]
kbanyas 234288 233733 Tue Sep 13 15:12:21 2022 3-03:22:04 sshd: kbanyas@pts/0