Linux htop command options
The htop
command in Linux is a powerful, interactive tool for monitoring system performance, including CPU usage, memory usage, and process management. It comes with several useful options that allow you to customize its behavior and output. Below, I’ll explain the most common htop
command options with examples.
Basic Syntax:
1. -d <delay>
- Purpose: Set the delay (in milliseconds) between updates.
- Example:
This command sets the delay between screen updates to 500 milliseconds. By default,
htop
updates every second.
2. -u <user>
- Purpose: Display processes for a specific user.
- Example:
This will display only the processes that belong to the user "john."
3. -p <pid>
- Purpose: Display information for a specific process ID (PID).
- Example:
This command will show information only for the process with PID 1234.
4. -C
- Purpose: Disable color output (useful for viewing output in a monochrome terminal or when logging to a file).
- Example:
This disables color, making the output plain text, which can be useful for scripts or logging.
5. -b
- Purpose: Start
htop
in batch mode. This mode is non-interactive and is useful for logging or redirecting the output to a file. - Example:
This runs
htop
in batch mode for one iteration and redirects the output tohtop_output.txt
. The-n 1
option ensures thathtop
runs for only one iteration before exiting.
6. -s <field>
- Purpose: Sort processes by a specific field.
- Example:
This will sort the processes based on CPU usage, displaying the highest CPU consumers at the top. You can also sort by other fields like
%MEM
for memory usage,PID
for process ID, etc.
7. -S
- Purpose: Display cumulative CPU time for processes, rather than the current CPU usage.
- Example:
This will display processes with cumulative CPU time, which gives you a sense of the total CPU time each process has consumed since it started.
8. -n <iterations>
- Purpose: Set the number of iterations
htop
should run before exiting. - Example:
This runs
htop
for 3 iterations and then exits. It's useful if you want a snapshot of the system for a set number of updates.
9. -s <column_name>
- Purpose: Sort processes by a specific column name.
- Example:
This will sort the processes by memory usage in descending order. You can also use
%CPU
,TIME+
, orPID
to sort by those columns.
10. -h
- Purpose: Display help (this is the default when you run
htop
without any options). - Example:
This shows help and a list of all the available commands and keybindings for interacting with
htop
.
11. -v
- Purpose: Display version information.
- Example:
This will display the version of
htop
installed on your system.
Example Usage:
Running
htop
with a custom delay:This will update the
htop
display every second (1000 milliseconds).Display processes only for a specific user:
This will show only processes running under the "root" user.
Run
htop
in batch mode and save the output:This will run
htop
for 5 iterations in batch mode and save the output tohtop_output.txt
.Sort processes by CPU usage:
This sorts processes by CPU usage, showing the processes with the highest CPU usage at the top.
Run
htop
for a specific process by PID:This will display detailed information about the process with PID 12345.
Interactive Features in htop
:
While htop
is running, you can use interactive commands to interact with processes and adjust the display:
- F1: Show help
- F2: Setup (for customizing the appearance of
htop
) - F3: Search for a process
- F4: Filter processes
- F5: Display processes in a tree view
- F6: Sort processes by a selected column
- F7: Decrease process priority (renice)
- F8: Increase process priority (renice)
- F9: Kill a process
- F10: Quit
htop
Summary of Common Options:
-d <delay>
: Set the update delay (in milliseconds).-u <user>
: Show processes for a specific user.-p <pid>
: Show details for a specific process.-C
: Disable color output.-b
: Run in batch mode (useful for logging).-s <field>
: Sort processes by a specific field.-S
: Show cumulative CPU time.-n <iterations>
: Set the number of iterations before exiting.-v
: Display version information.-h
: Display help.
htop
provides a more user-friendly, feature-rich experience than top
, with interactive features for sorting, filtering, killing, and renicing processes. You can also customize its output with various options to match your monitoring needs.