close
close

Manage Linux System Resources with These 7 Terminal Commands

Manage Linux System Resources with These 7 Terminal Commands

Not sure what’s hogging your Linux PC’s resources? There are many tools for obtaining information about your system and managing resources. Here are some you should know about to monitor processes, files, memory, and disk usage.

top: Process overview

the most popular in Linux terminology.the most popular in Linux terminology.

the most popular in Linux terminology.

One command I used to see what processes were running on my system was vertex. Think of it as the Linux equivalent of Windows’ task manager.

It is a full screen program that shows what is running on my system and the resources being used such as CPU and RAM. The display is updated every few seconds.

top shows which processes are running, their process IDshow much memory they use and who they belong to.

htop: like a top, but more colorful.

htop runs in the Linux terminal.htop runs in the Linux terminal.

htop runs in the Linux terminal.

htop is similar to topbut more colorful. I prefer it to htop, and I’m not alone. It seems to come pre-installed on many Linux distributions. One of its advantages over the regular old top is that the interface is colored and the bars at the top of the screen show resource usage. It’s also easy to customize the view, such as sorting by memory or CPU usage.

The user interface is also friendlier than the good old Top. htop seems to be installed by default on many distributions. If not, this is one of the first things I install on a new Linux system.

On a Debian or Ubuntu system, you can use the following command to install it:

sudo apt install htop

free: check your free memory

free is a simple command that lets you see how much free memory is available on your computer. When you type “free” at the Command Prompt, you’ll see how much physical RAM you’re using, as well as swap space or virtual memory.

By default, free shows free memory in blocks when you run the command without any arguments. The -f option will show it in “human-readable” formats such as gigabytes or megabytes.

free -h

Output of free -h showing free and virtual memory in Linux terminal.Output of free -h showing free and virtual memory in Linux terminal.

Output of free -h showing free and virtual memory in Linux terminal.

This allows you to see at a glance how much memory you are using in the terminal.

vmstat: virtual memory check

vmstat output in Linux terminal.vmstat output in Linux terminal.

vmstat output in Linux terminal.

vmstat shows some statistics about your swap space.

Linux, like other modern operating systems, uses virtual memory to use your storage for processes that don’t need RAM directly. This allows you to use more memory than is available in physical RAM, but memory usage is slower. Processes can be “replaced” or “replaced” as needed by the kernel. Although Windows has a page file, most Linux distributions create a special page partition upon login.

If you notice slow performance, you can run vmstat to see how much virtual RAM is being used. You can decide order a new flash drive. top and htop also show physical and swap memory.

vmstat will show how much memory is used as swap, how much is free, how much is used as cache, and how much is used in buffers. Much of this information will be of interest to system programmers, although knowing how much memory you’re using is essential to troubleshooting performance issues.

du and df: check disk space

Even though HDDs and SSDs have plenty of space these days, sometimes it seems like there’s never enough space. Standard Linux tools for checking disk space or du and df.

Output of du -h in the Linux terminal, showing disk file usage.Output of du -h in the Linux terminal, showing disk file usage.

Output of du -h in the Linux terminal, showing disk file usage.

du will list the size of the files in the directory. For example, to find out the size of files in /usr/local/bin:

du /usr/local/bin

df shows the available space on all connected storage devices. If you run df with path as an argument, you will see the free space on the device it is on.

df-h command showing disk usage in Linux terminal.df-h command showing disk usage in Linux terminal.

df-h command showing disk usage in Linux terminal.

For example, to check the root directory:

df /

By default, du and df show free space by block size. To see usage in “human-readable” units such as MB or GB, use the -h option in both programs.

lsof: check open files

Sometimes you may find that the shell won’t let you log out because the file is in use. You can use the lsof command to see what files are open. It will show you a list of currently open files. It will also show a list of devices since devices are also files in a Linux system. You can close or destroy the offending program and then log out.

lsof is passed through the head command to show open files in the Linux terminal.lsof is passed through the head command to show open files in the Linux terminal.

lsof is passed through the head command to show open files in the Linux terminal.

It can also be used to track unauthorized connections as network sockets will also be shown in this list. If you see an unfamiliar connection, it could be an attacker.

The most important information is the command name and the full path to the open file. They are located in the “COMMAND” and “NAME” fields in the table, which is printed in the terminal.

Uptime: How long does your machine last?

The uptime command displays the system uptime on the Linux terminal.The uptime command displays the system uptime on the Linux terminal.

The uptime command displays the system uptime on the Linux terminal.

The uptime command shows how long your machine has been running. It will show the current time, the system uptime since the last boot, the number of users currently logged in, and the average load for the last minute, 15 minutes, and 30 minutes.

It’s a useful tool for servers, but many Linux users also like to brag about their uptime. This is a simple command with fewer options. Even manual page short. You can use the -s option to show how the system booted by itself.

uptime -s

The output of uptime -s shows when the system was last booted.The output of uptime -s shows when the system was last booted.

The output of uptime -s shows when the system was last booted.