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]: Runshtopwith 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
htopwithout it being installed. Install it usingsudo apt install htop(Debian/Ubuntu) orsudo yum install htop(CentOS/RHEL/Fedora). - Not using arrow keys or function keys to navigate and manage processes, which limits interaction.
- Running
htopwithout root privileges when trying to see all processes; usesudo htopto 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
| Key | Action |
|---|---|
| Arrow Keys | Navigate process list |
| F3 | Search for a process |
| F4 | Filter processes |
| F5 | Tree view toggle |
| F6 | Sort by column |
| F9 | Kill a process |
| F10 | Quit 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.