Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

Real-Time Memory Monitoring in Linux with free -m and watch

When your Linux system starts slowing down, the first suspect is usually memory. Is RAM maxing out? Is swap being used? Is some process eating up everything?

Luckily, Linux offers simple yet powerful commands to help monitor memory usage β€” and two of the most underrated ones are:

  • free -m
  • watch -n 1 free -m

Together, they give you a real-time, clear view of your memory status, right from the terminal.

Let’s dive into what these commands do and how you can use them like a pro.


πŸ” What is free -m?

The free command shows how much memory and swap space is being used, free, cached, and available on your system.

The -m flag tells free to display the values in megabytes.

βœ… Basic Usage:

free -m

Sample Output:

              total        used        free      shared  buff/cache   available
Mem:           7824        1836         612         130        5375        5583
Swap:          2047           0        2047

Breakdown of the Output

ColumnMeaning
totalTotal RAM or swap space
usedMemory currently in use
freeMemory that is completely unused
sharedMemory shared between processes
buff/cacheMemory used by buffers and cache
availableEstimation of memory available for new processes

πŸ’‘ Pro Tip:

Don’t panic if used looks high. Linux uses free memory for caching to speed things up. The available column gives a better picture of what’s really usable.


πŸ” What is watch -n 1 free -m?

This command runs free -m every second, updating the output in real-time.

βœ… Command:

watch -n 1 free -m

What It Does:

  • watch runs a command repeatedly.
  • -n 1 means run it every 1 second.
  • So you get a live dashboard of memory usage.

πŸ’Ό When to Use These Commands?

  • 🐒 Your system is slowing down
  • 🧠 You’re debugging memory leaks
  • πŸ› οΈ You want to monitor how apps consume memory
  • πŸ” You’re watching memory usage during load tests

🧠 Common Use Cases

1. βœ… Monitor a Laravel app under load:

ab -n 1000 -c 10 http://localhost/api/test
watch -n 1 free -m

Watch how your app consumes memory during performance tests.


2. βœ… Detect Swap Usage:

If Swap used starts increasing, your physical RAM is full, and the system is using disk (much slower).

free -m | grep Swap

3. βœ… Combine with Process Monitoring:

Run in two terminals:

  • Terminal 1:
watch -n 1 free -m

Terminal 2:

htop

You’ll see which process is using the memory in real time.


πŸ“Œ Bonus Tip: Get a One-Liner Summary

free -m | awk 'NR==2{printf "Used: %sMB | Free: %sMB | Available: %sMB\n", $3,$4,$7}'

This outputs something like:

Used: 1856MB | Free: 612MB | Available: 5583MB

Perfect for scripts and logs.


🧠 Final Thoughts

Whether you’re a system admin or a developer managing servers, keeping an eye on memory is crucial. Tools like free -m and watch -n 1 free -m are simple, fast, and already built into every Linux distro β€” no setup required.

The next time your system lags or you run a big process, use these commands to stay one step ahead.

Related Posts

Fixing MySQL Error: Incorrect Definition of mysql.column_stats Table

The Problem While working on your MySQL server, you might come across this error in your error log: This error usually shows up after an upgrade or…

Fixing Laravel Migration Error: “Unknown Collation: utf8mb4_0900_ai_ci”

While working with Laravel and MySQL, you might run into an error during migrations like this one: Why This Happens The collation utf8mb4_0900_ai_ci is introduced in MySQL…

Why Dental Surgery Is Good and Important

Dental health plays a vital role in our overall well-being, yet it’s often overlooked until problems become serious. Dental surgery is a powerful solution that not only…

How to Get Cosmetic Surgery Covered by Insurance

Cosmetic surgery has become increasingly popular for individuals seeking to enhance their appearance or correct certain physical issues. While many people assume that cosmetic procedures are always…

htop Monitoring in Linux: The Ultimate Guide to Real-Time System Insights

When managing Linux systemsβ€”whether a small web server or an enterprise-grade VMβ€”real-time performance monitoring is critical. You want to know: Enter htop β€” the beloved, colorful, interactive…

Apache Benchmark (ab): A Simple Yet Powerful Tool for Web Performance Testing

Ever wondered how many users your website can handle before it slows down or crashes? Whether you’re running a blog, a Laravel app, or a full-blown e-commerce…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x