← Linux and the Command Line Lesson 27 of 51 · 5 XP

Memory and uptime: free and uptime

Theory

Machine translation, not yet reviewed by a native speaker.

free shows the RAM and swap:

free -h
               total        used        free      shared  buff/cache   available
Mem:           7.7Gi       2.1Gi       1.3Gi       180Mi       4.3Gi       5.2Gi
Swap:          2.0Gi          0B       2.0Gi

Don't be alarmed by a small free. Linux deliberately uses free memory for the file cache (buff/cache): that makes the disk faster. When programs need memory, the cache is given up. Look at the available column: that's how much can really be used.

Swap is space on the disk where the system moves rarely used memory. If swap is in heavy use and available is close to zero, there isn't enough memory, and everything will be slow.

uptime shows how long the system has been running without a reboot, and what the load is:

uptime
# 14:32:01 up 12 days,  3:41,  2 users,  load average: 0.15, 0.20, 0.18
uptime -p
# up 1 week, 5 days, 3 hours (GNU)

The three numbers in the load average are the average load over 1, 5 and 15 minutes. They show whether it's growing or falling.

A couple more useful commands: nproc — the number of processor cores, lscpu — details about the processor, uname -a — the kernel version.

Try it yourself: Programmers' Room → Linux · sh.

Sign up for free to mark finished lessons and track your progress.