pgrep is a bash command that looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout. All the criteria given as parameters to pgrep have to matched.
$ pgrep fi
— List the PID of process names match with “fi”.
$ pgrep -l fi
— Same as above and process name also get listed.
$ pgrep -vl fi
— List all processes, which name not match with “fi”.
$ pgrep -xl fi
— List all processes, which name exactly match with “fi”.
$ pgrep -f sbin
–List all processes, which are running from some sbin folder. It check the command line also.
$pgrep -c fi
–Show the count of matching processes.
$ pgrep -d, fi
— List the matching process id in CSV format.
$ pgrep -t tty1
— List the process controlling the term tty1.
$ pgrep -u root, jo
— List all processes owned by root and jo.
$ pgrep -u jo gnome
— List the process called sshd and owned by jo.
$ pgrep -n fi
— Show only the newest process.
$ pgrep -o fi
— Show only the oldest process.