pgrep
TLDR
Find process by name
SYNOPSIS
pgrep [-flnoxc] [-u user] [-g group] [-P ppid] [pattern]
DESCRIPTION
pgrep searches for processes by name or attributes, returning their PIDs. It's a more focused alternative to piping ps through grep.
Pattern matching is against the process name by default (executable name). The -f flag extends matching to the full command line including arguments. Regular expressions are supported.
Selection filters narrow results by user, group, terminal, or parent process. These can be combined for precise targeting. The -v flag inverts selection, finding processes that don't match.
Newest (-n) and oldest (-o) options return single matches, useful when multiple instances exist. Count mode (-c) reports how many processes match without listing them.
Output formatting options control delimiter and detail level. These enable integration with shell scripts and other tools.
PARAMETERS
-l, --list-name
List PID and process name.-a, --list-full
List PID and full command line.-f, --full
Match against full command line.-x, --exact
Match exactly (not substring).-n, --newest
Select newest (most recent) match.-o, --oldest
Select oldest (first) match.-c, --count
Count matches instead of listing.-d DELIM, --delimiter DELIM
Output delimiter (default: newline).-u USER, --euid USER
Match effective user ID.-U USER, --uid USER
Match real user ID.-g GROUP, --pgroup GROUP
Match process group.-G GROUP, --group GROUP
Match real group ID.-P PPID, --parent PPID
Match parent process ID.-t TERM, --terminal TERM
Match controlling terminal.-v, --inverse
Invert match (negation).-i, --ignore-case
Case-insensitive matching.
CAVEATS
Matches are substring by default - "sh" matches bash, fish, zsh. Use -x for exact matching. Process names may be truncated. Zombie processes may still match. Pattern is a regular expression. pgrep cannot find itself.
HISTORY
pgrep was introduced in Solaris 7 (1998) and ported to Linux as part of procps. It provides a cleaner interface than the traditional `ps aux | grep pattern` approach, avoiding the common "grep matching itself" problem. The tool is part of the procps-ng package on most Linux systems.


