The psgrep command is a handy utility in Unix-like operating systems for searching through the currently running processes. It’s essentially a combination of the ps and grep commands, making it easier to find specific processes without having to manually filter the output of ps.
Here’s how you can use psgrep:
- Basic Usage: To search for a process by name, simply type
psgrepfollowed by the name of the process. For example, to find all instances of a process namedfirefox, you would use:
psgrep firefox
- This command lists all processes that have the word “firefox” in their description.
- Case Sensitivity: By default,
psgrepsearches are case sensitive. You can make your search case-insensitive by using the-ioption:cssCopy codepsgrep -i firefox - Show Full Command: To see the full command line used to start each process (which can be truncated in standard output), use the
-foption:Copy codepsgrep -f firefox - Display Only PIDs: If you’re only interested in the Process IDs (PIDs), you can use the
-ooption:
psgrep -o firefox
- Exclude Certain Processes: You can exclude certain processes from the search results using the
--excludeoption. For example, to exclude thepsgrepprocess itself
psgrep firefox --exclude psgrep
- Help and Options: For a full list of options and more detailed help, you can always run
psgrepwith the--helpflag
grep --help
Remember, psgrep may not be installed by default on all Unix-like systems, so you might need to install it first using Brew, Apt or Yum.
