System and processes

The pgrep command

Finds processes by name and returns their PIDs. It is pkill's sibling without killing anything.

Syntax

pgrep [-f] [-x] [-l] [-a] [-n] PATRÓN

Most useful options

-lAlso shows the process name
-aShows the full command
-fSearches the full command line, not just the name
-xRequires an exact name match

Copy-ready examples

$ sleep 100 & && pgrep sleepPID of the sleep processes
$ sleep 100 & && pgrep -l sleepPID and name
$ sleep 100 & && pgrep -a sleepPID and full command

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Without -f it only searches the process name, not its arguments.
  • With no matches it prints nothing and exits with an error: it is not broken.

Related commands

FAQ

What is the difference from ps | grep?

pgrep does not count the grep process and offers -f and -x with precision.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course