Linux Commands

The pgrep Command Tutorial

There are multiple commands in Linux by which you can simplify your tasks and complete them right from the terminal. The pgrep command allows a user to find process IDs in the running program in the system’s current state.

The pgrep command is similar to grep. After executing the grep command, it also searches for the pattern and prints a matching text in the output. However, if you need to apply the type of processing for fetching, select the information about the currently running process. Here, pgrep comes into the picture to get more information. If you also want to learn pgrep, don’t worry because we will explain everything about the pgrep command in this guide.

The pgrep Command Tutorial

Let’s start with checking all options available in pgrep, so here is the basic command to check them out:

pgrep -h

Or

pgrep --help

To check the version of pgrep, execute the following command:

pgrep -V

Or

pgrep --version

pgrep provides the PIDs of the running process of the given name in the command. For example, we need to find the PID of Firefox, so we will execute the following command for it:

pgrep firefox

If you want to find the specific user’s details, then just add the username with the previous command.

You can change the delimiter as the PIDs in the output are delimited from the new line. So, use the -d option with the pgrep command for it:

pgrep -u morbius -d:

To list all processes with their respective names, you can run the following command in the terminal:

pgrep -u morbius -l

You can use the -i option to make the pgrep command case insensitive, since pgrep is case sensitive by default:

pgrep -i firefox

If you want to display the entire command that is used for launching every process, then use the -a option:

pgrep -u morbius -a

Use the -o option with the following pgrep command to identify the oldest process running in the system currently:

pgrep -u morbius -o -l

The -c option is used in the following pgrep command for printing the count of a matching process:

pgrep -c -u morbius

Conclusion

This article provided the pgrep command tutorial, which included everything you need to know about pgrep. We explained how to use different pgrep command options to track the running process directly from the terminal. We hope you found this article helpful. On the Linux Hint website, check the uploaded guides and command tutorials to help you work on Linux smoothly.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.