The pkill
command in the Debian Almquist Shell (dash) is used to terminate processes based on their names or other attributes. It allows users to kill processes without needing to look up their process IDs (PIDs), making it a convenient tool for managing running applications.
The basic syntax of the pkill
command is as follows:
pkill [options] [arguments]
-f
: Match against the full command line instead of just the process name.-n
: Kill the newest process matching the criteria.-o
: Kill the oldest process matching the criteria.-signal
: Specify a signal to send to the process (e.g., -9
for SIGKILL).-u
: Specify the user whose processes to kill.Here are several practical examples of using pkill
:
pkill firefox
This command will terminate all instances of the Firefox browser.
pkill -f "python script.py"
This command will kill all processes that have “python script.py” in their command line.
pkill -9 apache2
This command forcefully kills all instances of the Apache web server by sending the SIGKILL signal.
pkill -n ssh
This command will terminate the most recently started SSH session.
pkill -u username
This command will terminate all processes owned by the specified user.
pkill
, as it can terminate multiple processes at once.-n
or -o
options if you only want to kill the most recent or oldest instance of a process.pgrep
first to preview which processes will be affected before executing pkill
.