Quick Shell Tip: Remove grep command while grepping something using ps command
Generally you use ps command to find out all running process. You may also pipe out ps command output via grep command to pickup desired output.
Basically you don't want display grep command as the process.
Let us run combination of ps and grep command to find out all perl processes:
$ ps aux | grep perl
Output:
vivek 4611 0.0 0.7 10044 6068 ? Ss 02:40 0:00 /usr/bin/perl apps/monitor/gwl.pl root 4853 0.0 0.7 10044 6068 ? Ss 02:40 0:00 /usr/bin/perl /usr/share/webmin/miniserv.pl /etc/webmin/miniserv.conf vivek 5166 0.0 0.0 2884 748 pts/0 R+ 03:06 0:00 grep perl
In above example you are getting the grep process itself. To ignore grep process from output, type any one of the following:
$ ps aux | grep perl | grep -v grep
OR
$ ps aux | grep '[p]erl'
Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
You may also be interested in other helpful articles:
- Read UNIX/Linux system IP address in a shell script
- Quick tip: Easily find strings with grep color highlighting feature
- How to find out which network service are NOT linked against libwrap.s / tcpd (TCPWrapper)
- Shell script to watch the disk space
- Tutorial: How to use filters and regular expressions using grep, sed, and awk
Discussion on This Article:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: grep_command, grep_perl, ps_command



Also works when you’re grepping for something in the output of the history command.
Nice one. I am not going to use this - I really don’t mind the grep command appearing. Still, its clever.
This has been an annoyance of mine for awhile now. However, its a bit too syntactically taxing for the marginal gain.
Does anybody know how to set up an alias to accomplish the same goal?
Jerod,
alias not possible as passing args interpreted by shell at the time of creation. But something as follows should help out:
function pps(){ ps aux | grep "$@" | grep -v 'grep'; } pps perlVivek:
Thanks a lot. Added that function to my .bashrc and it works like a charm!
$ ps aux | grep ‘[p]erl’
can you explain how this work? regexp ?
Thanks for ur wonderful suggestion in adding to .bashrc……… Good… keep it up