The pkill
command in Bash is used to terminate processes based on their name or other attributes. It allows users to send signals to processes, making it a powerful 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 (e.g., -9
for SIGKILL).-u
: Specify the user whose processes to target.Here are some practical examples of using the pkill
command:
pkill firefox
This command will terminate all instances of Firefox.
pkill -9 chrome
This sends the SIGKILL signal to all Chrome processes, forcing them to close immediately.
pkill -f "python script.py"
This will terminate any process running the specified Python script.
pkill -n ssh
This command will terminate the most recently started SSH session.
pkill -u username
This will kill all processes owned by the specified user.
-9
, as it does not allow processes to clean up.pgrep
to preview which processes will be affected by your pkill
command before executing it.pkill
with other commands in scripts for automated process management.