Back to the command reference

pgrep

ProcessesFundamentals In simulator In real Linux

Find process IDs by name

Name: pgrep = process grep

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

pgrep looks up processes by name or other attributes and prints their PIDs. Unlike ps | grep it never matches itself, which makes it better in scripts.

Syntax

pgrep [OPTION]... PATTERN

Common options

-l / --list-nameAlso list the process name
-a / --list-fullShow the full command line too
-f / --fullMatch the full command line
-x / --exactThe name must match exactly
-u / --euid USEROnly a user's processes
-P / --parent PPIDOnly children of PPID
-n / --newestOnly the newest one
-o / --oldestOnly the oldest one
-c / --countOnly how many

Examples

  • $ pgrep nginx

    PIDs of nginx

    Explain
  • $ pgrep -lf python

    Python processes with their command lines

    Explain

Related