htop command in Linux explained.

This is the Linux Basic Command tutorial for the htop command.

htop command in Linux explained in detail with the installation in CentOS and Ubuntu.

htop command is to track the real-time processes. It is the same as the top command but it allows us to scroll up and down.

So with the help of htop command, you can track Memory Usage, CPU usage, CPU Process, and PID (Process ID).

Also, you can troubleshoot with the help of the htop command, What happens to the server? Hey! why it’s not working.

In this tutorial, we will focus on the 4 topics for the htop command in Linux.

  1. How to install htop command in CentOS distributors.
  2. How to install htop command in Debian distributors.
  3. htop command Output explained in Linux.
  4. htop command in Linux with examples.

How to install htop command in CentOS

So there is 2 ways to install htop command in CentOS,

  1. with yum command
  2. with rpm package

Install htop with yum command.

# yum install epel-release
# yum install htop

Install htop with rpm package.

So, first download the package of .RPM for htop with wget command.

# wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/h/htop-2.2.0-3.el7.x86_64.rpm

Once the .rpm gets downloaded, install with the rpm command.

# rpm -ivh htop-2.2.0-3.el7.x86_64.rpm

How to install htop command in Ubuntu

So lets install htop in Ubuntu 18 and Ubuntu 20 with apt & apt-get command.

Install htop in Ubuntu 18/20 with apt & apt-get command.

# sudo apt-get update
# sudo apt-get install htop

So the above command will be used in Ubuntu 18, update the Ubuntu repository then install the htop command.

# sudo apt update
# sudo apt install htop

So the above command will be used in Ubuntu 20, update the Ubuntu repository then install the htop command.

htop cheat sheet
Install htop command in CentOS 7 and CentOS 8

# yum install epel-release
# yum install htop
Install htop command in Ubuntu 16 and Ubuntu 18

# sudo apt-get install htop
# sudo apt install htop
htop change delay, htop set refresh rate in Linux.

Syntax:
# htop -d [tenths of seconds] 

Command:
# htop -d 30
**The refresh rate will be at every 3 seconds.**
htop command change colors, colours in Linux.

Command:
# htop -C
htop command sort by PID in Linux

Syntax:
# htop -s [field/column]

Command:
# htop -s PID
htop command sort by USER in Linux

Syntax:
# htop -s [field/column]

Command:
# htop -s USER
htop command sort by Memory and Memory Usage in Linux.

Syntax:
# htop -s [field/column]

Command:
# htop -s MEM%
htop command sort by CPU and CPU Usage in Linux.

Syntax:
# htop -s [field/column]

Command:
# htop -s CPU%
htop command sort by TIME in Linux.

Syntax:
# htop -s [field/column]

Command:
# htop -s TIME+
htop command sort by command in Linux.

Syntax:
# htop -s [field/column]

Command:
# htop -s Command
htop command tag or untag process in Linux.

# Interactive Key:
"Press SPACE" to tag or untag the Process, to untag all the process "press U or Shift + u"
htop command shows open file in Linux.

# Interactive Key:
"Press l"
htop command help in Linux.

Command:
# htop --help

# Interactive Key:
"Press F1"
htop settings, setup, configuration in Ubuntu and CentOS

# Interactive Key:
"Press F2" or "Shift + s"
htop command show tree view linux

Command:
# htop --tree

# Interactive Key:
"Press F5" or "Shift + s"
htop command kill multiple process

# Interactive Key:
"Press F9" >> then it will highlight on "15 SIGTERM" >> and "Press Enter" to Terminate the Signal, this will kill the selected process.
htop command monitor specific or multiple process

Syntax:
# htop -p [pid]
# htop -p [pid1,pid2,pid3]

Command:
# htop -p 1
**To monitor single process id**
# htop -p 1,6,443
**To monitor multiple process id**
htop command monitor specific user.

Syntax:
# htop -u [User]

Command:
# htop -u tastethelinux


htop command output explained in Linux.

We have divided the htop command output into three parts the UPPER part, Lower part and the Interactive part.

htop command in Linux explained CentOS 7 Ubuntu 18.

So, here there is a screenshot of the htop command, here we can see all the running process.

— UPPER PART of htop command in Linux —

So the UPPER part is consists of CPU, RAM, SWAP Utilisation, Number of tasks, threads, load average and UPTIME.

htop command in Linux explained CentOS 7 Ubuntu 18.

CPU shows the number of cores, Memory shows the usage of the Memory, There are 138 tasks which is divided into 331 threads and only 1 running process.

After that, there is a Load average of the server for 1 minute, 5 minutes and 15 minutes.

The Last is the UPTIME of the server, you can add more parameters in the UPPER Part by using the interactive key F2.

— LOWER PART of htop in Linux —

So the lower part consists of process activity, which was displayed as columns. We can also add the Columns/Fileds in the htop output.

htop command in Linux explained CentOS 7 Ubuntu 18.
  • PID: The process ID of the Processes.
  • USER: The Username of the Process owner. Who has started that process?
  • PRI: The Priority of the process, its nice value plus twenty.
  • NI: The Nice value of the processes which are running, it is from 19 to – 20. 19 is a very low priority and – 20 is a high priority.
  • VIRT: The Size of the Virtual Memory of the process.
  • RES: The resident set size (text + data + stack) of the process.
  • SHR: The size of the process’s shared pages.
  • STATE (S): The state of the running process: S for sleeping (idle), R for running, D for disk sleep, Z for zombie, T for traced or suspended, W for paging
  • CPU%: The percentage of the CPU time that the process is currently using.
  • MEM%: The percentage of memory the process is currently using.
  • TIME+: The process has spent in user and system time.
  • Command: The full command line of the process

You can add more Fields and column you can add by using the Interactive key F2.

INTERACTIVE PART of htop in Linux —

The Interactive part consists of some Function Keys of our keyboards, from which you can manage the screen of htop.

htop command in Linux explained CentOS 7 Ubuntu 18.

On the above reference screenshot, we can see F1, F2, F3, and etc are the function keys which is used to manage the meters, display options, colours, and Columns.

htop command in Linux with examples.

So here we will see the htop command options and examples in Linux.

htop change delay, htop set refresh rate.

So, here we will set the refresh rate of the htop command. It delays between the updates.

# htop -d 30

We have used -d option and 30 means it will update the screen of htop at every 3 seconds.

This is because of htop works in the tenths of seconds. So if you want to refresh every 10 seconds then use the command,

# htop -d 100

htop command change colors, colours.

So if you have to change from default mode to monochrome mode, you can use -C option.

htop command in Linux explained CentOS 7 Ubuntu 18.
# htop -C

Also, we can “Press F2” and we can see the third setup is of “Colors” here we can see more options for the look and feel of the htop screen.

htop command in Linux explained CentOS 7 Ubuntu 18.

htop command sort by PID, Memory Usage, CPU Usage, time, user, and command or order by PID, Memory Usage, CPU Usage, time, user and command.

So with the help of htop command, we can sort by PID’s, by the user, by CPU usage, by Memory Usage, by TIME and by Command.

htop command in Linux explained CentOS 7 Ubuntu 18.
# "Press F6" to Sort the Process.

So, by “Press F6” we can see the fields of the htop command has been displayed and select the particular Fields for sorting.

— htop sort by PID —

Suppose we have sort by PID then we will use “-s option” with the field name which is PID

# htop -s PID

— htop sort by USER —

If we want to sort by user then use “-s option” with USER column.

# htop -s USER

The order is from the alphabet order A on the top and Z at the END of the htop screen.

— htop sort by Memory and Memory Usage —

Let’s sort by the Memory Usage or RAM or by Memory then we will use -s option with MEM% which is the name of the field.

# htop -s MEM%

So by the above command, we can also see which process is using the more Memory. We can also use the “M” key to sort by memory.

— htop sort by CPU and CPU Usage —

So for the CPU usage will use “-s option” with CPU% field. Which is the process has the High CPU Utilisation that will be displayed at the top in the htop screen.

# htop -s CPU%

We can also use the “P” key to sort by CPU Usage on the htop screen.

— htop sort by TIME —

Suppose we have to see which process is taking more time, or we have to sort the process by the TIME it is running.

# htop -s TIME+

So here we have used -s option with TIME+ column to sort htop screen by time. We can also use the “T” key to sort by TIME.

— htop sort by command —

What if we have to sort the process or command in htop, so the field or column name is “Command”, so we will use “-s option” with Command

# htop -s Command

htop tag the process in Linux.

Tagging the process is much needed in htop screen because if many processes are running we can’t find our main process, so we will tag the process.

# "Press SPACE" to tag or untag the Process, to untag all the process "press U or Shift + u"

htop show open files

If we have to check the files open in a process, just “press l” on the htop screen and it will display the snapshot.

# "Press l"

htop help in Linux

The htop command has more options, it is possible we forget some of the options, that we take help from the htop screen

# "Press F1"

We can also use –help option with htop, but it will only show you the options that you can use, not the interactive commands.

# htop --help

htop settings, setup, configuration in Ubuntu and CentOS

The great part is that we can set up or configure the htop, as our requirement.

So there four configuration part in the htop: 1. Meters, 2. Display options, 3. Colors and 4. Columns.

Also there is the htop configuration file named as “htoprc” is in “$HOME/.config/htop/” directory

So by “pressing F2” you can configure the htop screen as per your need.

# "Press F2"
  1. METERS

Meters have the left and right column, and an interesting part that we can change this setting by using arrow keys and the space bar and save the settings by using F10.

The CPU usage is showing us the “BAR” style but it contains “TEXT”, “GRAPH” and “LED” Style. Same for the Memory, Swap and other columns.

Also, there is an Available meter from this you can select the other meters by “pressing Enter” and can use arrow keys to shift into Left or Right Columns.

Suppose we have to select a Clock Meter and it should display into the left column.

# Press F2 >> Select Meters >> Use arrow key to go to Available meters >> select Clock >> Press Enter >> It will come at the Right column but we want it at the Left column use of arrow key and move it to the left column >> Then press enter to lock the Meter of Clock >> Press F10.

The interesting part you can use your Mouse to do this above activity.

2. DISPLAY OPTIONS.

The Display options are used to display the different views on the htop screen. you can select and deselect by using “SPACE”.

3. Colors

So here we can select the colours for the htop by using “SPACE” and it is set by default, there are more options for the colours.

4. Columns

So now we will select the columns, there are more available columns in our htop screen.

you can select any of the columns by “pressing Enter” and “press F10” to save the configuration.

htop command search next in Linux

So in htop, we can search the process name by using the function key F3 and F4.

# "Press F3", we will search mysql process name >> And press Enter >> To search the next mysql process "Press F3".
# "Press F4" this will filter only that processes whose names will be matched by your searching pattern. 

htop show tree view linux

So in htop command we can also see the process as a tree view for that we have two options, can use –tree or use the Interactive key

By using Interactive key we will use the function keys

# "Press F5"
# htop --tree

So by using this option we can view the process in tree format.

htop kill multiple process

To kill the process is one of the dangerous things in the server but still, sometimes it is important to kill the process, so to delete any process will use an interactive key.

# "Press F9" >> then it will highlight on "15 SIGTERM" >> and "Press Enter" to Terminate the Signal, this will kill the selected process.

So SIGTERM is the signal which is used to terminate the process, but be careful before terminating any process.

htop command monitor specific or multiple processes

So what if we have to monitor a specific PID for that we will use “-p option”.

Now suppose we have to monitor the “process id 1”, then we will use below command.

# htop -p 1

And now we will see how to monitor multiple process using -p option.

# htop -p 1,443

Here we have monitored two process id 1 and 443 using htop command.

htop command monitor specific user in Linux, CentOS, Ubuntu.

So will use -u option to monitor specific user, and this will show the only process of a given user.

# htop -u syslog

So here monitoring the user syslog which is running on the server, also you can “press u” on the htop screen and will display the list of users.

And we can select the user which we have to monitor and “press Enter”.

Thanks for Reading the POST for htop, want to learn about top command output explained or top command in Linux can refer the links.

[wp_quiz id=”4146″]

htop sort by memory, htop command not found, htop command in linux, htop command in linux explained, htop install, htop command in ubuntu, htop sort by memory, linux htop command, linux htop command explained, linux htop install, linux htop load average, linux htop kill process, htop command in centos, linux htop sort by memory

One Reply to “htop command in Linux explained.”

Give your valuable time