Member-only story
Here are possibly the next ten Linux commands you’ve never used. They can be quite useful.
1. pgrep
With pgrep
, the p
suggests it’s related to processes, and since it includes grep
, it’s obviously a grep command related to processes. However, its main purpose is to list process IDs.
It allows users to find processes by their attributes, such as process name or other characteristics, without needing to know the PID in advance.
For example:
$ pgrep -u root sshd
1234
5678
In this example, “1234” and “5678” are the process IDs of the processes that match the specified criteria (e.g., owned by a specific user and with a specific name).
This command is the same as:
$ ps -ef | egrep '^root' | awk '{print $2}'
2. pstree
The pstree
command displays the processes in a tree-like structure. Here’s an example:
$ pstree
init-+-acpid
|-auditd-+-python
| `-{auditd}
|-automount---4*[{automount}]
|-backup.sh---sleep
|-dbus-daemon
|-events/0
|-events/1
|-hald---hald-runner---hald-addon-acpi
|-httpd---10*[httpd]
|-irqbalance
|-khelper
|-klogd…