The three commands that show you what's using RAM
The fastest way to see how much memory your Linux system is using is to open a terminal and type free -h. This shows your total RAM, how much is in use, and how much is available — all in human-readable numbers like gigabytes instead of raw bytes. If you want more detail about which programs are eating memory, use top or htop to see a live list ranked by memory use. The ps command lets you check one specific program's memory without watching everything at once.
Each command answers a different question. free tells you the overall picture. top and htop show you what's running right now and how much each thing costs. ps is for when you already know which program you want to check. Most people start with free -h to see if they have a problem, then move to top if they need to find what's causing it.
Key Takeaways
- Type free -h in a terminal to see your total RAM, used RAM, and available RAM in gigabytes or megabytes.
- top shows every running program ranked by memory use, updating in real time as you watch.
- htop works like top but is easier to read and lets you kill programs directly from the list.
- The "available" number in free is more useful than "free" because Linux uses spare RAM for caching, which it will drop if a program needs it.
- If a program is using too much memory, you can stop it with kill or restart it from the command line.
Understanding the free command output
When you type free -h, you get a table with two rows: one for memory and one for swap. The memory row shows total (your installed RAM), used (what's in use right now), free (completely unused), and available (free plus memory Linux can reclaim from cache). The number that matters is available, not free, because Linux fills unused RAM with cached data from your disk to speed things up. When a program needs that space, Linux drops the cache when ready.
Swap is disk space your system uses as overflow when RAM runs out. If your swap is being used heavily, your system is slow because disk is much slower than RAM. A small amount of swap use is normal. Heavy swap use means you need more RAM or you have a program using too much memory.
Run free -h a few times over a few minutes. If the available number stays roughly the same, your system is fine. If available keeps dropping and used keeps climbing, something is leaking memory — using more and more over time without releasing it.
Using top to find which program is using memory
top shows every running program in a list, sorted by CPU use by default. Press M to sort by memory instead, and the biggest memory hogs jump to the top. The RES column shows actual RAM each program is using. The VIRT column shows virtual memory (RAM plus swap plus memory the program requested but hasn't actually used yet), so ignore it — RES is what matters.
Watch top for 30 seconds to see if any program's memory keeps climbing. If it does, you've found a leak. Press Q to quit top. If you want to kill the program, note its PID (process ID, the number in the leftmost column), then type kill PID in a new terminal window.
top updates every few seconds by default. If you want it slower or faster, press D to change the delay. Press H to see all the keyboard shortcuts.
htop: a friendlier version of top
htop works like top but is easier to use. It shows colors, lets you scroll with arrow keys, and displays memory as a bar graph so you can see at a glance how full your RAM is. Press F6 to sort by memory use. The columns are the same as top — RES is the real memory number.
htop may not be installed by default. If you type htop and get "command not found", install it with sudo apt install htop on Ubuntu or Debian, or sudo yum install htop on Red Hat or CentOS. Once it's installed, it's usually faster to use than top because you don't have to remember keyboard shortcuts.
To kill a program in htop, highlight it with arrow keys and press K. It will ask you to confirm. This is safer than using kill because you can see exactly which program you're stopping.
Checking a single program's memory with ps
If you know the name of the program you want to check, ps is faster than opening top. Type ps aux | grep programname, replacing "programname" with what you're looking for. For example, ps aux | grep firefox shows every Firefox process running.
The output shows columns including %MEM (percentage of total RAM) and RSS (actual RAM in kilobytes). If you want the number in megabytes, type ps aux --sort=-%mem | head -n 11 to see the top 10 memory users with the biggest ones first. The head -n 11 part limits it to 11 lines (the header plus 10 programs).
This command is useful when you suspect one specific program is the problem and you want a quick answer without watching a live display.
What to do if memory use is too high
If your available memory is consistently below 10 percent of your total RAM, your system will slow down because it's swapping to disk. The first step is finding what's using it with top or htop. If it's a program you don't need, close it or uninstall it. If it's a program you do need, you have three options: restart the program (which clears memory leaks), upgrade to more RAM, or run fewer programs at once.
Some programs leak memory — they use more and more RAM over days or weeks without releasing it. If restarting the program fixes it temporarily, the program has a leak and you may need to report it to the developers or switch to an alternative. If the problem comes back when ready after restart, the program genuinely needs that much memory and you need more RAM.
If your system is slow but memory looks fine, the problem is probably CPU or disk, not RAM. Use top to check the CPU column, or run iostat -x 1 to see disk activity.
Memory commands quick reference
| Command | What it shows | When to use it |
|---|---|---|
| free -h | Total, used, and available RAM | Quick check of overall memory status |
| top | All running programs ranked by CPU, press M for memory | Finding which program uses the most memory |
| htop | Same as top but with colors and easier navigation | When top is installed and you want a friendlier display |
| ps aux | grep name | Memory use of one specific program | Checking one program without opening a live display |
| kill PID | Stops a program by its process ID | Closing a program that's using too much memory |
Frequently Asked Questions
What's the difference between used and available memory?
Used memory includes programs plus cached data from disk. Available memory is what a new program can actually use right now. Linux caches disk data in unused RAM to speed things up, so available is always smaller than free. When a program needs RAM, Linux drops the cache when ready, so available is the number that tells you if your system has room.
Why does my memory use keep climbing even when I'm not opening new programs?
A program is leaking memory — using more RAM over time without releasing it. Restart the program to clear it. If it happens again within hours, the program has a bug. If it only happens after days, it's a slow leak and you can live with restarting weekly, or switch to a different program.
Is swap bad for my system?
A little swap use is fine. Heavy swap use means your system is slow because disk is much slower than RAM. If swap is climbing fast, you need more RAM or you need to close programs. Check with free -h — if swap is more than 10 percent of your total RAM and climbing, you have a problem.
Can I kill a program from the command line without using top?
Yes. Find its PID with ps aux | grep programname, then type kill PID. The program will close gracefully. If it doesn't close after a few seconds, type kill -9 PID to force it, though this can cause data loss if the program had unsaved work.
What does VIRT memory mean in top?
VIRT is virtual memory — the total amount of memory a program has requested, including RAM it's actually using plus memory it reserved but hasn't touched yet. RES is what it's actually using. Watch RES, not VIRT, because VIRT can be misleading.