Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$ ps aux | grep -i ssh
USER      4364  0.0  0.0   9004  1032 ?        Ss   12:20   0:00 ssh -v -fND localhost:4000 USERNAME@SERVER-IP-ADDRESS

$ pgrep localhost:4000

Why doesn't this work?

share|improve this question
up vote 18 down vote accepted

By default, pgrep(1) will only match against the process name. If you want to match against the full command line, use the -f option:

$ pgrep -f localhost:4000
share|improve this answer

Have a look at the man page for pgrep. It is not just an alias for running ps with a bunch of columns and then greping the text output. It actually searches specific fields for values. By default, it only looks at the process name when doing a search and returns the PID. You can search the full command line by adding the -f option. You can also search several other fields that might be useful such as matching the terminal where a process is running or the group id.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.