How can I find determine real-time system performance parameters such as memory usage, CPU usage, disk usage from the terminal in Linux. I have asked Google but have not found a succinct suggestion. I am trying to divorce myself from the distro bundled utilities and do this from terminal
3 Answers
Many of the commands you want "do one thing, and do it well". On the one hand, this means they all look a bit different. On the bright side, this can make it more manageable - to learn one thing at a time :-). I will try to answer directly and succinctly. You asked for the top three:
df -h
- filesystem usage levels. This includes in-memory filesystems (tmpfs
).free -h
- for remaining "available" memory, and how much swap is used. The other fields might not mean what you think, sorry! See below.top
- show processes sorted by cpu usage.- press q to quit.
- also shows overall CPU usage, divided into a few different types
- also shows some, but not all, of the output of
free
df
and free
just run once, and print the current results. If you want to see a "live" view of the current results in a terminal, put watch
in front of the command. To stop watch
, press Ctrl+c.
4. You didn't mention disk activity, i.e. reads/writes. But this is also shown, per-process, in recent versions of gnome-system-monitor. Heavy disk activity can sometimes make the system feel very slow. To see this information on the command-line, use sudo iotop
.
iotop
is usually not installed by default. If a program is not installed, Linux Mint (and other distributions) will offer to install it, when you try to run it!
In theory, you might want to see both current values, and previous history. LIke the graphs in gnome-system-monitor. There is a slightly less common command for this. Use vmstat 5
to see, over 5 second intervals: usage of swap and memory, swap activity, disk activity (io
), and cpu activity. You will probably need to resize the terminal window, to make it a little wider :-).
Understanding Linux memory usage
This can get a bit tricky. I am stealing the quote block below from linuxatemyram.com.
(I think this is a good example where using the common, single-purpose tool can help focus your learning. And when you have a specific question, it might already be documented. E.g. see the manual page man free
. Or the support communities have likely already answered it somewhere :-).
A healthy Linux system with more than enough memory will, after running for a while, show the following expected and harmless behavior:
free
memory is close to0
used
memory is close tototal
EDIT: this part is outdated :-(.
used
no longer includesbuff/cache
. You can just ignoreused
, because either way it is redundant with the other fields!available
memory (or "free + buffers/cache") has enough room (let's say, 20%+ of total)swap used
does not changeWarning signs of a genuine low memory situation that you may want to look into:
available
memory (or "free + buffers/cache") is close to zeroswap used
increases or fluctuatesdmesg | grep oom-killer
shows the OutOfMemory-killer at work
Per-process memory usage
Per-process memory usage can also be tricky! top
shows per-process memory usage. But top
is misleading for some types of program, including firefox
and google-chrome
. This is because top
counts shared memory multiple times, in every process that shares that memory :-).
sudo smem -t
shows better memory usage numbers, in the PSS
column.
sudo smem -t -P firefox
is a pretty neat command. It adds up how much memory my favourite browser is eating.
Using sudo
here allows smem
to work on running processes that are not owned by your login user. If you don't need that, you can run it without sudo
.
Propaganda for atop
atop is like a swiss army chainsaw multi-tool. It can show most of the above information, apart from disk space usage.
For example: sudo atop -R
enables the PSIZE
column, which is equivalent to the smem
column PSS
. Press m to show this memory information. Press Shift+m to sort by memory usage.
In general, the top half of atop
tries to show the most important information and highlight potential concerns. It leaves out the values which are currently less significant, to make the best use of the screen space.

- 50,249
Use the command top
to display real-time information about active processes. By default top
shows units in kilobytes but you can change this by using ShiftE to change the units of the summary information above the list of current processes and e to change the units of the list of currently running processes.
Pressing Shiftm sorts the list by memory or you can press Shiftf to open a field management window where you can select which column header to use to sort (s)the list in descending order
As for disk usage you can use the commands df
and du
:
df
shows the available space on the file system (e.g. ntfs, ext4, fat32) that contains each file name argument. For example, if you want to see the free space on an external hard drive use the commanddf -h /Path/to/external_harddrive
which will output the available space on the file system of the external drive mounted on the directory/Path/to/external_harddrive
. If no file is specified thendf
will show the available space on all mounted file systemsdu
will show the disk usage of the specified file. When a directory is specified as an argument todu
,du
will show the disk usage of the directory recursively which meansdu
will show the disk usage in a depth-first traversal (process each directory's content before the directory itself) again and again until it has shown the disk usage of all files or directories in the specified directory. Use the option--max-depth=LEVEL
to makedu
only show the disk usage of all files or directories the specified level or below the directory given todu
as an argument. For exampledu -h --max-depth=1 ~/Documents
will printout the size of all files and directories 1 level or less below the directoryDocuments
(level 1 is the lowest level below a directory tree). If you don't want the size of all files and directories to be shown use the-s
(summary) option to only show the total size of theDocuments
directory without the individual sizes of theDocument
directory's contents
Note: the short option -h
(--human-readable
in long form) means human readable which makes the output of du
or df
easier for the human brain to process into something meaningful

- 1,106
Kernel writes the memory/cpu/etc usage to files under /proc
directory. For example, you can get the realtime memory usage in the file /proc/meminfo
.
[root@localhost ~]# cat /proc/meminfo
MemTotal: 131832516 kB
MemFree: 79406996 kB
MemAvailable: 121444792 kB
Buffers: 2112 kB
Cached: 41602056 kB
SwapCached: 0 kB
Active: 30971812 kB
Inactive: 18976428 kB
Active(anon): 8353396 kB
Inactive(anon): 8332 kB
Active(file): 22618416 kB
Inactive(file): 18968096 kB
Like this, proc/stat
file will give you a pathetic amount of details about your CPU. Explore the /proc directory, you will find more.

- 307
-
while keeping
man proc
open in another window, to refer to. (Ctrl+F to search inside the web page, or "/" key to search inside theman
command). – sourcejedi Jul 01 '19 at 22:02
atop
feels to me like a good potential answer, you might focus on explaining what you want, that theatop
command you already use does not have or does not show in the desired way... – sourcejedi Jul 02 '19 at 08:01