Linux htop command overview

htop is a monitoring tool that allows you to see how much CPU, memory, and swap space your Linux server is using. It also shows you a list of all the processes that are running on your server, and how much CPU and memory each process is using. htop can be used to find out which processes are using the most resources and to kill processes that are misbehaving. It's an alternative to the classic top utility, but with additional features and a more user-friendly interface that allows for easier monitoring and management of system processes.

Install htop

  1. To use htop, first, install it on your system. On most Linux distributions, you can install htop through the package manager.

     sudo apt update
     sudo apt install htop
    
  2. After installation, to start htop, run:

     htop
    

Customize htop and Keyboard Shortcuts

In most cases, servers will not have a mouse attached, so keyboard shortcuts must be learned.

Navigation:

  • Arrow keys: Move the selection cursor up, down, left, and right to navigate through the list of processes.

  • PgUp/PgDn: Scroll the process list a page up and down.

  • Home/End: Jump to the top or bottom of the process list.

  • Mouse: You can also use the mouse to select items.

Display and Sorting

  • F1 or h: Open the help screen, which displays the keyboard shortcuts.

  • F2 or S: Open setup, where you can configure htop settings, including which columns are displayed.

    • Right arrow: Move to the next section in the setup menu.

    • Up and down arrows: Select an item in the setup menu.

    • Delete: Remove an item from the setup menu.

    • Enter: Add an item to the setup menu.

  • F3 or /: Incremental process search. Type the name of the process to highlight it.

  • F4: Filter processes. Only processes matching the filter will be displayed.

  • F5 or t: Tree view toggle. Display processes in a tree structure.

  • F6 or < and \>: Sort processes by different criteria, such as CPU or memory usage. Press F6 then use the arrow keys to select the sort criterion.

  • F7 and F8: Adjust the nice value (priority) of a process down or up. Lower numbers mean higher priority.

  • F9: Kill the process

    SIGTERM allows a process to clean up and terminate gracefully, making it the preferred method for stopping processes. SIGKILL is more abrupt and should be used as a last resort when a process does not respond to SIGTERM or other more gentle methods of termination, as it does not allow the process to clean up resources, which might lead to system instability or resource leaks.

  • F10, q, or Ctrl+C: Quit

  • Space: Tag or untag a process. Tagged processes can be acted on collectively.

  • U: Untag all processes.

  • u: Filter the process list by user.

  • Shift + p: Sort the process list by CPU usage.

  • Shift + m: Sort the process list by memory usage.

References:

  1. Youtube: Linux Crash Course - htop

  2. htop.dev

  3. https://github.com/htop-dev/htop