The “htop” Command in Linux [7 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The htop command in Linux is a very advanced command. The htop command when used shows all the current processes of the system. And the htop command also shows a list of all the running processes throughout the system.

But this command is user interactive. Which means it enables the use of the mouse. Users can scroll through the top page if they want. In this article, I will explain how to use the htop command and I will also show you some useful examples.

A. Description

The htop command in Linux does the same function as the top command. But the difference is htop is more modern than the top. The htop command is more interactive than the top command.

Note: The htop command is not always preinstalled on all Linux distributions. To install it on Debian/Ubuntu-based system, type sudo apt install htop

B. Syntax

The syntax for the htop command is very simple. Which is the htop command followed by its various options and flags. The syntax is given below.

htop [-dCFhpustvH]
Note: The traditional switches `-‘ and whitespace are optional. Anything bound by the square brackets is optional

C. Options

Many useful options are available for the htop command. I have listed some of the most used ones here. However, if you want to know more about options for the htop command you can always check the man page for the htop command.

man htop

Useful Options

  • -u, –user: This option only shows the process for a specific user.
  • -M, –no-mouse: This option disables the interactive mouse operation.
  • –tree: This option Shows system processes as a tree view.
  • -V, –version: Shows version information.
  • -h, –help: Shows help message and exit.
Note: The options in Linux CLI (Command Line Interface) are all case-sensitive. So, be cautious while using them. Options starting with (–) are long forms of options. Long Forms have the same meaning as Short Forms.

Practical Examples of the “htop” Command in Linux

The htop command is very easy to use. It is one of the most important commands of the Linux CLI when it comes to system diagnosis. Here I have given some examples of the htop command.

Example 1: Showing Table of Process Using the “htop” Command in Linux

If I want to view the system summary or all the running processes on the system interactively I will have to use the htop command in Linux. The way to do that is very simple. Follow the steps below to see how this works,

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

htop

➌ Now, press the ENTER button.

Output >

The upper portion of the picture shows the total system summary and the lower portion shows the list of all running processes in the system. To halt this operation you have to press the q button.

Using the htop command in linux


Similar Readings


Example 2: Sorting Linux Processes Using the “htop” Command in Linux

If you want to sort the process you will use the same htop command in Linux. Follow the steps below to know how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

htop

➌ Now, press the ENTER button.

➍ Now, press the F6 button.

This will give you a window like below

sorting using the htop command in linux

So, click on any of the fields that you want to sort by. Here I will sort by the PID(Process ID).

➎ Now, click on PID.

➏ Now, press the ENTER button.

Output >

As you can see from the picture below that the PID column is sorted.

using htop command in linux for sorting

Example 3: Showing Linux Processes for a Specific User Using the “htop” Command in Linux

If you want to show the Linux processes of a certain user you have to use the option(-u). You will have to use the command then the option and the user name. Now follow the steps below.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

htop -u akash

➌ Now, press the ENTER button.

Output >

As you can see that the htop operation printed the process list for the user akash.

showing specific user list using the htop command in linux


Similar Readings


Example 4: Showing Help Page for “htop” Command in Linux

If you want to see the help page you will use the same htop command in Linux. For this, you will have to use the option (-h). Follow the steps below to know how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

htop -h

➌ Now, press the ENTER button.

Output >

As you can see that the htop operation printed the help page.

Showing the help page

Example 5: Using “htop” Command in Linux with Redirection

In this example, I will redirect the output of the htop command to a different file. Now follow the steps below to see how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

htop -h > File1.txt

➌ Now, press the ENTER button.

➍ Type the following command in the command prompt:

cat File1.txt

➎ Now, press the ENTER button.

Output >

As you can see that the htop operation printed the help page for the htop command in Linux.  But instead of printing it on the terminal, I redirected that output to File1.txt.

using redirection with htop command

Note: The cat command is used for viewing file content.

Similar Readings


Example 6: Showing Linux Processes as Tree View Using the “htop” Command in Linux

If you want to see the Linux processes as a tree view you have to use the option (–tree). Now follow the steps below to see how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

htop --tree

➌ Now, press the ENTER button.

Output >

As you can see that the htop operation printed the tree view of the list.

Showing the tree view

Note: You can just use the F5 button to toggle between the list view and the tree view.

Similar Readings


Example 7: Using “htop” Command in Linux to Disable the Mouse in List/Tree View

If I want to disable the functionality of the mouse inside the processes list I will have to use the option (-M) with the command htop. Now follow the steps below to see how this works.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

htop -M

➌ Now, press the ENTER button.

Output >

As you can see that the htop operation was successful. Here the mouse function is disabled. I used the arrow keys to navigate.

using the _M option

Note: You can just use the F buttons to perform various operations, which is at bottom of the picture.

Conclusion

In this article, I have tried to show you how the htop command works. And I have also included some useful examples. If you go through this article properly, you should be able to use the command htop properly on your own.


Similar Readings

Rate this post
Md. Rafsan Zani

Hello, I’m Md. Rafsan Zani. I have recently completed my Undergraduate from the Bangladesh University of Engineering and Technology (BUET). Currently, I’m pursuing higher studies abroad. I’m really interested in computer science and would like to learn a lot about the wonderful world of computers. Currently, I’m working as a Linux Content Developer Executive and find Linux really interesting. I certainly would like to learn more about Linux and implement them in my future studies. Read Full Bio

Leave a Comment