Here is a simple example to find PID of ssh-agent for username without showing PID of grep process itself:
ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $1 $2;}' If you want for example to kill ssh-agent for current user you might use following command:
kill `ps xu | grep "${USER}.*[ ]/usr/bin/ssh-agent" | awk '{print $2;}'` To create a handy alias add to your .bashrc file the following:
function function1 () { ps xu | grep "$1.*[ ].*$2.*" | awk '{print $1 $2;}' } alias mygrep="function1" And to use alias do: . /etc/profile #to make alias usable my-grep ${USER} ${PROCESS_PATH} my-grep ${USER} fnord
P.S. I've only tested these commands on Ubuntu. Also you need to know full path of the executable you are searching such as /usr/bin/ssh-agent in this examples