Bash ps command execution output command

Excluding the ps Command from Its Own Output Using Bash ps Command

About how to exclude the ps command itself from the output when running the ps command on the Bash language command line of Linux computers and servers. When you run the ps command, the ps command itself and the commands piping it also end up in the output.

Shou Arisaka
2 min read
Nov 2, 2025

About how to exclude the ps command itself from the output when running the โ€œpsโ€ command on the Bash language command line of Linux computers and servers.

When you run the ps command, the ps command itself and the commands piping it also end up in the output.

For example, if you want to check if node.js might be running in the background in the current shell.

tty="$( tty | ag -o '\d+' )" ; ps aux | ag "(tty|pts)/${tty}" | awk '!/\s(Ss)\s/' 

This produces output like the following:

Image

yuis     17361  0.0  0.0 1175236 26304 pts/8   Sl   00:49   0:01 node tmp.js
yuis     18990  0.0  0.0 873500 26608 pts/8    Sl   01:21   0:00 node tmp.js
yuis     20377  0.0  0.0 874012 26656 pts/8    Sl   01:48   0:00 node tmp.js
yuis     24704  0.0  0.0  16676  1868 pts/8    R    02:44   0:00 ps aux
yuis     24705  0.0  0.0  11416  1080 pts/8    R    02:44   0:00 ag (tty|pts)/8
yuis     24706  0.0  0.0  25676  1824 pts/8    R    02:44   0:00 bash -l -i

Of this output, the important part is only the following:

yuis     17361  0.0  0.0 1175236 26304 pts/8   Sl   00:49   0:01 node tmp.js
yuis     18990  0.0  0.0 873500 26608 pts/8    Sl   01:21   0:00 node tmp.js
yuis     20377  0.0  0.0 874012 26656 pts/8    Sl   01:48   0:00 node tmp.js

If you want output like this, do the following: Since the output of ps aux is sorted by command start time, you can delete the line containing ps aux and subsequent lines with sed โ€˜/ps aux/,+1 dโ€™.

text processing - Remove line containing certain string and the following line - Unix & Linux Stack Exchange

tty="$( tty | ag -o '\d+' )" ; ps aux | ag "(tty|pts)/${tty}" | awk '!/\s(Ss)\s/' | sed '/ps aux/,+1 d'

Image

Share this article

Shou Arisaka Nov 2, 2025

๐Ÿ”— Copy Links