0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use htop Command in Linux: Syntax and Examples

Use the htop command in Linux to launch an interactive process viewer that shows running processes, CPU, memory usage, and more. Simply type htop in the terminal and use arrow keys or function keys to navigate and manage processes.
📐

Syntax

The basic syntax of the htop command is simple:

  • htop: Starts the interactive process viewer.
  • htop [options]: Runs htop with optional flags to customize behavior.

Common options include:

  • -d <delay>: Set the delay between updates in tenths of seconds.
  • -u <user>: Show processes for a specific user only.
  • -p <pid>: Show only specific process IDs.
bash
htop [options]

# Examples:
htop
htop -d 10
htop -u username
htop -p 1234,5678
💻

Example

This example runs htop to show all processes interactively. You can use arrow keys to scroll, F9 to kill a process, and F10 to quit.

bash
htop
Output
An interactive screen showing a list of running processes with columns like PID, USER, CPU%, MEM%, TIME+, and Command. The top shows CPU, memory, and swap usage bars.
⚠️

Common Pitfalls

Some common mistakes when using htop include:

  • Trying to run htop without it being installed. Install it using sudo apt install htop (Debian/Ubuntu) or sudo yum install htop (CentOS/RHEL/Fedora).
  • Not using arrow keys or function keys to navigate and manage processes, which limits interaction.
  • Running htop without root privileges when trying to see all processes; use sudo htop to see system-wide processes.
bash
Wrong:
htop
# May not show all processes without sudo

Right:
sudo htop
# Shows all processes with full permissions
📊

Quick Reference

KeyAction
Arrow KeysNavigate process list
F3Search for a process
F4Filter processes
F5Tree view toggle
F6Sort by column
F9Kill a process
F10Quit htop

Key Takeaways

Run htop in the terminal to start an interactive process viewer.
Use arrow keys and function keys (F3-F10) to navigate and manage processes.
Install htop if not present using your package manager.
Use sudo htop to see all system processes with full permissions.
Customize htop with options like -d for update delay or -u for user-specific processes.