How to Check Memory and CPU Usage on a Linux Server (htop, free and uptime)

When a server feels slow, the question is always the same: what's it busy doing? Three commands answer it. htop shows everything live, free tells you about memory, and uptime gives you the load average — one number that sums up how overworked the machine is.
Quick reference
| Task | Command | |
|---|---|---|
| Live view of everything | htop (install: sudo apt install htop -y) | |
| Memory in plain numbers | free -h | |
| How busy, in one line | uptime | |
| Top 5 memory hogs | `ps aux --sort=-%mem | head -6` |
| Top 5 CPU hogs | `ps aux --sort=-%cpu | head -6` |
| Number of CPU cores | nproc |
1. htop
sudo apt install htop -y
htop
The top shows a bar per CPU core, a memory bar and a swap bar. Below is every process, sorted by CPU use.
- F6 changes the sort column (pick MEM% to find memory hogs).
- F4 filters by name — type nginx to show only those.
- F9 kills the selected process (choose 15 SIGTERM first; 9 SIGKILL if it won't die).
- F10 or q quits.
Green in the memory bar is used by programs; yellow/orange is cache, which the system gives back the moment a program needs it. Only green matters.
2. free
free -h
total used free shared buff/cache available
Mem: 7.7G 2.1G 0.4G 12M 5.2G 5.3G
Beginners panic at the tiny free figure. Ignore it. Linux deliberately uses spare RAM as a cache for files, and that cache counts as "used". The number to watch is available — that's what programs can actually have. If available is under about 10% of total, you're genuinely short.
The Swap line below it: if swap "used" is climbing, the server is running out of real memory and is paging to disk, which is why it's slow.
3. Load average
uptime
10:15:02 up 12 days, 3:40, 1 user, load average: 0.52, 0.80, 1.10
The three numbers are the average load over the last 1, 5 and 15 minutes. Compare them to your core count (nproc). On a 4-core machine, a load of 4.0 means every core is fully busy; 8.0 means things are queuing. A load under the core count is fine.
If the 1-minute figure is high but 15-minute is low, something just started. The other way round, something's been chewing for a while.
4. Find the culprit without htop
ps aux --sort=-%cpu | head -6
ps aux --sort=-%mem | head -6
The second column is the process ID; the last is the command. sudo kill PID asks it to stop. More in the next tutorial.
5. Disk activity
Sometimes the CPU is idle and memory is fine but the server still crawls. That's often the disk. sudo apt install iotop -y and sudo iotop -o shows which process is reading and writing.
Troubleshooting
htop shows CPU 100% on one core but the server works fine. One single-threaded job is maxing a core. Normal for a backup or a compile; it'll finish.
Memory "available" keeps shrinking day by day. A program is leaking memory. Find the grower with ps aux --sort=-%mem and restart it (sudo systemctl restart name).
Load is high but CPU bars are low. Processes are waiting on disk or network. Check iotop, and df -h in case the disk is full.
A process called kswapd0 is using CPU. The server is out of memory and swapping hard. Add RAM, add swap (tutorial 21), or stop something.
Wrapping up
htop for the live picture, free -h and the available column for memory, uptime for the load average against your core count. Between them they tell you in thirty seconds whether a slow server is CPU, memory or disk — and which process to blame.
