The fastest way to check memory in Linux

The free command shows your total memory, how much is in use, and how much is available in a single line. Open a terminal and type free -h to see the results in gigabytes instead of kilobytes — the -h flag means "human-readable". The output shows RAM in the first row and swap memory in the second.

If you want to watch memory change in real time, use top or htop. Type top and the screen updates every few seconds, showing which programs are using the most memory at the top of the list. Press q to exit. The htop command works the same way but with a cleaner layout — you may need to install it first with sudo apt install htop on Ubuntu or sudo yum install htop on Red Hat systems.

Key Takeaways

  • The free -h command shows total, used, and available memory in one quick output.
  • The top command displays memory use by individual programs and updates in real time.
  • The ps command lets you check memory for a single program without watching the whole system.
  • Memory marked "available" is not wasted — Linux uses it for caching, and programs can claim it when needed.

Understanding the free command output

When you run free -h, you see columns labeled total, used, free, shared, buff/cache, and available. The total is your installed RAM. The used column shows memory actively claimed by programs. The free column is memory sitting empty, which is rare on a running system.

The buff/cache column is the key to reading this correctly. Linux automatically fills unused memory with cached data from your disk — this speeds up repeated file access. This memory is not wasted; the system releases it instantly when a program needs it. The available column tells you how much memory programs can actually claim right now, including cached memory the system will free up. This number matters more than the "free" number for understanding whether your system has breathing room.

Checking memory for a single program

If you want to know how much memory one specific program is using, the ps command shows it without the overhead of watching the whole system. Type ps aux | grep programname, replacing "programname" with the name of the program you want to check. The output includes a column labeled VSZ (virtual memory size) and RSS (resident set size, the actual RAM in use).

For a cleaner view, use ps aux --sort=-%mem | head to list the top ten programs by memory use. The --sort=-%mem part orders them from highest to lowest, and head shows only the first ten lines. If you want to see more or fewer programs, change the number after head - — for example, head -20 shows the top twenty.

Using vmstat for memory trends over time

The vmstat command shows memory statistics at intervals you choose, which helps you spot whether memory use is climbing or staying steady. Type vmstat 1 5 to see five snapshots one second apart. The columns show free memory, buffer memory, cache memory, and swap use.

This is useful when you suspect a program has a memory leak — a bug that causes it to use more and more memory over time. Run vmstat while the program is running, and watch whether the "free" column drops steadily. If it does, the program is likely the culprit. For longer monitoring, you can redirect the output to a file: vmstat 5 100 > memory.log records 100 snapshots five seconds apart and saves them to a file you can review later.

Checking swap memory and what it means

Swap is disk space your system uses as overflow when RAM fills up. It is much slower than RAM, so heavy swap use means your system is struggling. The free -h command shows swap in the second row. If the "used" column under swap is zero or very small, your system has plenty of RAM and is running well.

If swap use is high, your system is pushing data to disk because RAM is full. This slows everything down noticeably. Check which programs are using the most memory with top, close unnecessary ones, or add more RAM if you can. You can also check swap use per program with grep VmSwap /proc/[pid]/status, replacing [pid] with the process ID — find the PID in the output of top or ps.

Memory information in the /proc filesystem

Linux stores detailed memory information in the /proc filesystem, a virtual directory the kernel creates. The file /proc/meminfo contains the same information as free but broken down into more categories. Type cat /proc/meminfo to see the full list, or cat /proc/meminfo | grep MemAvailable to pull out just one line.

Each running program has its own folder in /proc named after its process ID. Inside that folder, the file status shows memory use for just that program. For example, if a program has process ID 1234, you can see its memory with cat /proc/1234/status | grep VmRSS. This is how system monitoring tools gather their data behind the scenes.

Frequently Asked Questions

Why does my system show almost no free memory even though nothing is running?

Linux fills unused RAM with cached data from your disk to speed up file access. This cache is not wasted — the system releases it instantly when a program needs memory. Look at the "available" column in free -h, not the "free" column. If available memory is high, your system is fine.

What is the difference between VSZ and RSS in the ps output?

VSZ (virtual memory size) is the total memory a program has claimed, including memory it is not actively using right now. RSS (resident set size) is the actual RAM the program is occupying. RSS is the number that matters for understanding real memory use. A program might have a large VSZ but small RSS if it allocated memory it is not touching.

How do I know if my system needs more RAM?

If swap use is consistently high and your system feels slow, you likely need more RAM. Run free -h repeatedly over a few hours while doing your normal work. If the "available" column regularly drops below 10 percent of your total RAM, adding more memory would help. If available memory stays above 20 percent, you have enough.

Can I reduce memory use by clearing the cache?

You can clear the cache with sudo sync; sudo echo 3 > /proc/sys/vm/drop_caches, but there is no reason to do it. The cache speeds up your system, and the memory is not wasted — it is released instantly when needed. Clearing the cache actually makes your system slower until the cache rebuilds.