0
0
Linux CLIscripting~5 mins

top and htop (live monitoring) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes your computer feels slow or you want to see what programs are using the most power. The tools top and htop help you watch your computer's activity live, showing which programs use the most memory and CPU.
When your computer is running slow and you want to find which program is causing it.
When you want to check how much memory or CPU your programs are using right now.
When you need to stop a program that is stuck or using too much power.
When you want to watch your system's activity during a heavy task to see how it behaves.
When you want a simple way to see all running programs and their resource use.
Commands
This command starts the top tool, showing a live list of running programs and their CPU and memory use.
Terminal
top
Expected OutputExpected
top - 15:00:00 up 1 day, 3:22, 2 users, load average: 0.15, 0.10, 0.05 Tasks: 120 total, 1 running, 119 sleeping, 0 stopped, 0 zombie %Cpu(s): 5.0 us, 2.0 sy, 0.0 ni, 92.0 id, 1.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 8000000 total, 2000000 free, 3000000 used, 3000000 buff/cache KiB Swap: 2000000 total, 2000000 free, 0 used. 4000000 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1234 user 20 0 500000 30000 10000 S 5.0 0.4 0:10.00 myapp 5678 user 20 0 400000 20000 8000 S 2.0 0.3 0:05.00 bash
This command starts htop, a colorful and easier-to-use version of top with interactive controls.
Terminal
htop
Expected OutputExpected
htop - Interactive process viewer [Colorful display with CPU bars, memory bars, and a list of processes] Use arrow keys to navigate, F9 to kill a process, F10 to quit.
If htop is not installed, this command will show an error. You can install it with your package manager.
Terminal
htop
Expected OutputExpected
bash: htop: command not found
This command installs htop on Debian/Ubuntu systems so you can use it.
Terminal
sudo apt-get install htop
Expected OutputExpected
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: htop 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 100 kB of archives. After this operation, 300 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 htop amd64 2.2.0-2build1 [100 kB] Fetched 100 kB in 1s (100 kB/s) Selecting previously unselected package htop. (Reading database ... 200000 files and directories currently installed.) Preparing to unpack .../htop_2.2.0-2build1_amd64.deb ... Unpacking htop (2.2.0-2build1) ... Setting up htop (2.2.0-2build1) ... Processing triggers for man-db (2.9.1-1) ...
sudo - Run the command with administrator rights needed for installation
Key Concept

If you remember nothing else from this pattern, remember: top and htop show live system activity so you can find and manage resource-heavy programs easily.

Common Mistakes
Trying to run htop without installing it first
The system will say 'command not found' because htop is not installed by default on many systems.
Install htop using your system's package manager before running it.
Not using sudo when installing htop
Without sudo, the install command will fail due to lack of permissions.
Use sudo before the install command to get administrator rights.
Confusing top's keyboard commands with htop's
top and htop have different keys for actions like killing a process, which can cause confusion.
Learn the specific keys for each tool; for example, htop uses F9 to kill a process.
Summary
Use 'top' to see a live list of running programs and their resource use.
Use 'htop' for a more user-friendly, colorful, and interactive system monitor.
Install htop with 'sudo apt-get install htop' if it is not already available.