Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'See complete output of ps command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
See complete output of ps command
Authored by: geordie on Jul 26, '05 02:57:00PM
I just put the following in my .bashrc file and when I need to find a specific process I type psgrep processname.

psgrep() { ps -acux | grep -i $1 | grep -v grep }

You will need to type source ~/.bashrc to make it take affect immediately for the open window.

[ Reply to This | # ]

See complete output of ps command
Authored by: sweth on Jul 26, '05 03:32:17PM

As long as we're rehashing old unix tricks, and in the same vein as the "useless use of cat" comments, the second grep in your psgrep isn't necessary, and under some circumstances can actually hide relevant results.

The "proper" way to do this is to make sure that the regex that you are looking for does not actually match itself. The easiest way to do this is to replace one character from the regex with a character class that only matches that character; for example, the regex "[v]i" will match the string "vi", but will not match the string "[v]i", so a "ps auwwx | grep '[v]i'" won't include either of its subcommands in its results.

To automate this for a function, you can do something like

function psgrep {
ENDING="${1#?}"
ps auwwx | grep -i "[${1%${ENDING}}]${ENDING}"
}

.



[ Reply to This | # ]