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.
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]
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.
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.
Similar Readings
- The “time” Command in Linux [4 Practical Examples]
- The “tty” Command in Linux [4 Practical Examples]
- The “uptime” Command in Linux [5 Practical Examples]
- The “vmstat” Command in Linux [6 Practical Examples]
- The “uname” Command in Linux [11 Practical Examples]
- The “apt-get” Command in Linux [10 Practical Examples]
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
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.
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.
Similar Readings
- The “free” Command in Linux [8 Practical Examples]
- The “getent” Command in Linux [11 Practical Examples]
- The “groupadd” Command in Linux [7 Practical Examples]
- The “addgroup” Command in Linux [7 Practical Examples]
- The “groups” Command in Linux [6 Practical Examples]
- The “firewall-cmd” Command in Linux [7 Practical Examples]
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.
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.
Similar Readings
- The “groupmod” Command in Linux [5+ Practical Examples]
- The “id” Command in Linux [7+ Practical Examples]
- The “service” Command in Linux [6 Practical Examples]
- The “sestatus” Command in Linux [4 Practical Examples]
- The “shutdown” Command in Linux [7 Practical Examples]
- The “finger” Command in Linux [6 Practical Examples]
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.
Similar Readings
- The “dmesg” Command in Linux [7+ Practical Examples]
- The “install” Command in Linux [6+ Practical Examples]
- The “reboot” Command in Linux [3 Practical Examples]
- The “sync” Command in Linux [8 Practical Examples]
- The “chage” Command in Linux [7 Practical Examples]
- The “env ” Command in Linux [9 Practical Examples]
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.
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
- The “sudo” Command in Linux [8 Practical Examples]
- The “df” Command in Linux [11 Practical Examples]
- The “apt” Command in Linux [13+ Practical Examples]
- The “top” Command in Linux [8 Practical Examples]
- The “passwd” Command in Linux [7 Practical Examples]
- The “enable” Command in Linux [6 Practical Examples]
FUNDAMENTALS A Complete Guide for Beginners