# Linux htop command overview

[`htop`](https://htop.dev/) 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.
    
    ```bash
    sudo apt update
    sudo apt install htop
    ```
    
2. After installation, to start `htop`, run:
    
    ```bash
    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.
        
    
    ![](https://i.imgur.com/nl4t89a.png align="center")
    
* **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.
    
    ![](https://i.imgur.com/SPGQMKz.png align="center")
    
* **F5** or **t**: Tree view toggle. Display processes in a tree structure.
    
    ![](https://i.imgur.com/KpAv360.png align="center")
    
* **F6** or **&lt;** and **\&gt;**: Sort processes by different criteria, such as CPU or memory usage. Press F6 then use the arrow keys to select the sort criterion.
    
    ![](https://i.imgur.com/qTLtnXs.png align="center")
    
* **F7** and **F8**: Adjust the nice value (priority) of a process down or up. Lower numbers mean higher priority.
    
* **F9**: Kill the process
    
    ![](https://i.imgur.com/75pxHEP.png align="center")
    
    `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.
    
    ![](https://i.imgur.com/FVEiyeI.png align="center")
    
* **U**: Untag all processes.
    
* **u**: Filter the process list by user.
    
    ![](https://i.imgur.com/4RJe5ym.png align="center")
    
* **Shift + p**: Sort the process list by CPU usage.
    
    ![](https://i.imgur.com/S9gpb5v.png align="center")
    
* **Shift + m**: Sort the process list by memory usage.
    
    ![](https://i.imgur.com/Ma4d307.png align="center")
    

## References:

1. [Youtube: Linux Crash Course - htop](https://www.youtube.com/watch?v=tU9cO9FwDx0)
    
2. [htop.dev](https://htop.dev/)
    
3. [https://github.com/htop-dev/htop](https://github.com/htop-dev/htop)
