htop Command
The htop command is an interactive process viewer and system monitor for Linux and Unix systems. It provides a more user-friendly and feature-rich alternative to the traditional top command, with color-coded displays, mouse support, and intuitive navigation.
Syntax
Description
The htop command displays running processes in an interactive, real-time interface. Unlike the traditional top command, htop provides a more intuitive user experience with color coding, horizontal and vertical scrolling, mouse support, and easier process management.
Key features:
- Color-coded process list and system information
- Mouse support for clicking and scrolling
- Tree view showing process relationships
- Horizontal and vertical scrolling
- Easy process filtering and searching
- Function key shortcuts for common operations
📦 Installation
htop is not always installed by default. Install it using your package manager:
- Ubuntu/Debian:
sudo apt install htop - CentOS/RHEL:
sudo yum install htop - Fedora:
sudo dnf install htop - Arch Linux:
sudo pacman -S htop - macOS:
brew install htop
Advantages over top
- Visual appeal: Color-coded interface with progress bars
- Mouse support: Click to select processes and navigate
- Easier navigation: Arrow keys and scrolling support
- Tree view: See parent-child process relationships
- Better filtering: Easy process filtering and searching
- Function keys: Clear shortcuts displayed at bottom
- No learning curve: More intuitive for beginners
Function Keys
| Key | Function | Description |
|---|---|---|
F1 |
Help | Show help screen with all commands |
F2 |
Setup | Configuration menu (colors, columns, etc.) |
F3 |
Search | Search for processes by name |
F4 |
Filter | Filter processes by text string |
F5 |
Tree | Toggle tree view (process hierarchy) |
F6 |
SortBy | Choose sorting column |
F7 |
Nice- | Decrease process priority (increase nice) |
F8 |
Nice+ | Increase process priority (decrease nice) |
F9 |
Kill | Send signal to process (kill menu) |
F10 |
Quit | Exit htop |
Examples
Basic usage
htop -d 10 # Update every 1 second (10 tenths)
htop -u john # Show only john's processes
htop -p 1234,5678 # Monitor specific PIDs only
Start htop with different options and filtering
Interactive workflow
htop
# Common workflow:
# F5 - Toggle tree view to see process relationships
# F6 - Sort by different columns (CPU, Memory, etc.)
# F4 - Filter processes by name
# F9 - Kill selected process
# F10 - Quit htop
Typical interactive session for system monitoring
Process management
# 1. Use arrow keys to select a process
# 2. Press F9 to open kill menu
# 3. Choose signal (SIGTERM, SIGKILL, etc.)
# 4. Confirm to send signal
# Or use F7/F8 to change process priority
Manage processes directly from the htop interface
Filtering and searching
# F3 - Search for specific process name
# F4 - Filter to show only matching processes
# Type process name and press Enter
# ESC - Clear filter/search
Find and focus on specific processes
Customization
# F2 - Open setup menu
# Configure:
# - Display options (colors, meters)
# - Columns to show
# - Available meters
# - Colors and appearance
Customize htop appearance and functionality
htop vs top Comparison
htop Advantages
- Color-coded interface
- Mouse support
- Tree view of processes
- Easier navigation
- Better process management
- More intuitive
top Advantages
- Available on all systems
- Lower resource usage
- Better for scripting
- Batch mode support
- More portable
- Standard Unix tool
💡 Tips and Best Practices
- Use tree view (F5): Better understanding of process relationships
- Filter processes (F4): Focus on specific applications or users
- Sort by different metrics (F6): Find CPU or memory bottlenecks
- Use mouse: Click on processes and scroll for easier navigation
- Customize display (F2): Show only relevant information
- Learn function keys: Much faster than using mouse for everything
Common Use Cases
- System monitoring:
htop(general overview) - Find resource hogs: F6 to sort by CPU or memory
- Process troubleshooting: F5 for tree view, F4 to filter
- Kill hung processes: Select process, F9 to kill
- Monitor specific user:
htop -u username - Performance analysis: Use color bars and sorting options
Troubleshooting
- "htop: command not found": Install htop using package manager
- Colors not showing: Check terminal color support
- Mouse not working: Ensure terminal supports mouse events
- Display issues: Try resizing terminal or press F2 for setup
- Permission errors: Some process details require root access