free Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
The 'free' command in Linux is a powerful tool used to display the total amount of free and used memory (RAM) in the system, as well as the buffers and cache used by the kernel. This information is essential for system administrators and users to monitor and manage memory usage.
Linux free Command Syntax
The syntax for the free command is as follows:
Where:
- options: Flags that modify the behavior of the free command.
free Command Options:
- -b: Display memory size in bytes.
- -k: Display memory size in kilobytes (default).
- -m: Display memory size in megabytes.
- -g: Display memory size in gigabytes.
- -h: Display memory size in a human-readable format (e.g., 1K, 234M, 2G).
- -t: Display a line containing the totals.
- -s N: Continuously display the report every N seconds.
- -c N: Display the result N times, then exit. Requires the -s option.
- --help: Display the help message and exit.
- --version: Display version information and exit.
Example Usages
-
Display memory usage in the default format (kilobytes).:
Output:
Explanation: The output shows memory usage in kilobytes, with columns for total, used, free, shared, buffers/cache, and available memory.
-
Display memory usage in a human-readable format.:
Output:
Explanation: The output shows memory usage in a human-readable format, such as M for megabytes and G for gigabytes.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Tips
- Combine the -t option with -h for a more comprehensive and human-readable report.
Advanced Use Cases of free Command in Linux
-
Display memory usage every 5 seconds for a total of 3 times.:
Output:
Explanation: The -s and -c options allow you to monitor memory usage over a period of time and for a specific number of iterations.
-
Display memory usage in gigabytes, with totals.:
Output:
Explanation: The output shows memory usage in gigabytes, and includes a line displaying the total memory for each column.
-
Display memory usage in megabytes, updating every 2 seconds.:
Output:
Explanation: The -s option allows you to monitor memory usage in real-time, with a specified interval between updates.
Turn Learning into Career Growth
Conclusion
-
The 'free' command in Linux displays memory usage information.
-
Various options are available to modify the output format and behavior.
-
The -h option provides a human-readable format for easier interpretation.
-
Combining -s and -c options allows monitoring memory usage over time and for a specified number of iterations.