The pgrep
command in the Debian Almquist Shell (dash) is used to search for processes currently running on the system based on their names or other attributes. It returns the process IDs (PIDs) of the matching processes, making it a useful tool for managing and monitoring system processes.
The basic syntax of the pgrep
command is as follows:
pgrep [options] [arguments]
-u USER
: Search for processes owned by the specified user.-f
: Match against the full command line instead of just the process name.-n
: Only return the newest (most recently started) process.-o
: Only return the oldest (least recently started) process.-l
: List the process names along with their PIDs.Here are some practical examples of using the pgrep
command:
pgrep bash
pgrep -u username
pgrep -f "python script.py"
pgrep -n ssh
pgrep -l httpd
pgrep
in combination with other commands like kill
to terminate processes by their names.pgrep
with the -f
option to ensure you are matching the correct command line.pgrep
is case-sensitive by default. Use the -i
option for case-insensitive matching.