0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use pkill Command in Linux: Syntax and Examples

The pkill command in Linux lets you stop processes by their name or other attributes. You just run pkill process_name to kill all processes matching that name quickly and easily.
📐

Syntax

The basic syntax of pkill is simple and flexible:

  • pkill [options] pattern

Here, pattern is usually the process name or a part of it. Options let you refine which processes to target, such as by user or signal.

bash
pkill [options] pattern
💻

Example

This example shows how to kill all running processes named firefox:

bash
pkill firefox
⚠️

Common Pitfalls

One common mistake is using pkill without checking which processes will be affected, which can stop unintended programs. Another is forgetting that pkill matches partial names, so pkill ssh kills all processes with "ssh" anywhere in their name.

To avoid this, use the -x option to match the exact process name:

bash
# Wrong: kills all processes containing 'ssh'
pkill ssh

# Right: kills only processes named exactly 'ssh'
pkill -x ssh
📊

Quick Reference

OptionDescription
-u userKill processes owned by the specified user
-xMatch the exact process name
-signalSend a specific signal instead of default SIGTERM (e.g., -9 for SIGKILL)
-fMatch against the full command line, not just the process name

Key Takeaways

Use pkill process_name to kill processes by name quickly.
Add -x to match the exact process name and avoid accidental kills.
Use -u user to target processes by a specific user.
Specify signals like -9 to force kill if needed.
Always double-check which processes will be affected before running pkill.