CloudsArk
Commands Linux

pkill Command Examples in Linux

Practice useful pkill command examples for everyday Linux administration and troubleshooting.

pkill Command Examples in Linux

Introduction

These examples show practical ways to use pkill on a Linux terminal. Each example is written so you can adapt it for administration or troubleshooting.

Example 1: Basic Usage

pkill firefox

This is the simplest form of the command and is a good starting point before adding options.

Example 2: Common Admin Task

sudo pkill -HUP rsyslogd

This example reflects a common task on RHEL, Rocky Linux, AlmaLinux, or similar systems.

Example 3: Useful Option

pkill -u student

This option helps narrow the result, change behavior, or handle a more realistic target.

Example 4: Real-World Scenario

pkill -f "python app.py"

Use this pattern when the task moves beyond a single basic command.

Example 5: Verification

pgrep -a firefox

Example output:

2345 /usr/lib64/firefox/firefox
2351 /usr/lib64/firefox/firefox -contentproc

Common Mistakes

  • Using a broad pattern that matches unrelated processes.
  • Using -f without previewing with pgrep.
  • Forgetting that pkill may affect multiple processes at once.

Quick Reference

pkill firefox
sudo pkill -HUP rsyslogd
pkill -u student
pkill -f "python app.py"
pgrep -a firefox

Summary

Good pkill usage means choosing the right option, keeping the target clear, and verifying the result with output you can explain.