Friday, May 16, 2008

Remove grep from grep output of ps command


You might always see the "grep" as the list of processes when you grep for a particluar process.

$ ps -ef | grep xscreensaver
jsaikia 4050 1 0 May14 ? 00:00:00 xscreensaver -nosplash
jsaikia 14282 14245 0 16:54 pts/2 00:00:00 grep xscreensaver

If you want not to print it the output, you can do "grep -v grep".

$ ps -ef | grep xscreensaver | grep -v grep
jsaikia 4050 1 0 May14 ? 00:00:00 xscreensaver -nosplash

One more way:

$ ps -ef | grep [x]screensaver
jsaikia 4050 1 0 May14 ? 00:00:00 xscreensaver -nosplash

And if you want to make that a alias kind of function in your .bash_profile, make an entry like this in your .bash_profile


PS(){
ps -ef | grep "$@" | grep -v 'grep'
}


so that

$ PS xscreensaver
jsaikia 4050 1 0 May14 ? 00:00:00 xscreensaver -nosplash

No comments:

© Jadu Saikia www.UNIXCL.com