Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
function command in Linux with examples
Next article icon

free Command in Linux with examples

Last Updated : 09 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

While using LINUX there might come a situation when you are willing to install a new application (big in size) and you wish to know the amount of free memory available on your system. In LINUX, there exists a command line utility for this and that is the ‘free’ command which displays the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel. This is pretty much what free command does for you.

Table of Content

  • What is Linux free Command?
  • Options of Linux free Command
  • Basic Usage free Command
  • Usage and Examples of free command with options
  • Importance of Linux free Command

What is the ‘free’ Command?

The `free` command in Linux is the one that facilitates with providing the overview of system memory utilization. It displays all the details regarding the RAM usage such as how is the total, what is used, and free memory including buffers and cached data, aiding in real-time monitoring of memory resources. It acts as essential command for administrators and users to assess system performance, allocate resources effectively, and identify potential memory-related issues promptly.

Syntax:

The basic syntax of the “free” command is as follows:

free [OPTION]

Common Options of ‘free’ Command

As ‘free’ displays the details of the memory related to your system , its syntax doesn’t need any arguments to be passed but only options which you can use according to your wish.

The following are the some of the optiosn of linux free command:

Options Description
-k, –kilo Displays memory usage in kilobytes (default).
-m, –mega Displays memory usage in megabytes.
-g, –giga Displays memory usage in gigabytes.
–tera Displays memory usage in terabytes.
-h, –human Automatically scales all output columns to the shortest three-digit unit and displays the units (B, K, M, G, T).
-c, –count Displays the output ‘c’ number of times; works with the -s option.
-l, –lohi Shows detailed low and high memory statistics.
-o, –old Disables the display of the buffer-adjusted line.
-s, –seconds Continuously displays the output after ‘s’ seconds delay. Uses the usleep system call for microsecond resolution delay times.
-t, –total Adds an additional line in the output showing column totals.
–help Displays a help message and exits.
-V, –version Displays version information and exits.

Basic Usage of ‘free’ Command

The following command helps in finding the usage of ram memory in the system:

free

The following screenshot illustrates with displaying the usage of ram memory:

free command in Linux

Free command without any option shows the used and free space of swap and physical memory in KB

When no option is used then free command produces the columnar output as shown above where column:

  1. total displays the total installed memory (MemTotal and SwapTotal i.e present in /proc/meminfo).
  2. used displays the used memory.
  3. free displays the unused memory.
  4. shared displays the memory used by tmpfs(Shmen i.e. present in ‘/proc/meminfo’ and displays zero in case not available).
  5. buffers displays the memory used by kernel buffers.
  6. cached displays the memory used by the page cache and slabs(Cached and Slab available in ‘/proc/meminfo’).
  7. buffers/cache displays the sum of buffers and cache.

Usage and Examples of free command with options

The following are options and examples discussing the usage of free command with options:

1. Using ‘-b’ (Displaying Output in Bytes)

It just displays the output in unit bytes. The following is the command of its usage:

free -b
free -b option

2. Using ‘-k’ (Displaying Output in Kilobytes)

This option displays the result in kilobytes. The following is the command of its usage:

free -k
free -k options

3. Using ‘-m’ (Displaying Output in Megabytes)

This option displays the result in megabytes. The following is the command of its usage:

free -m
free -m option

4. Using ‘-g’ (Displaying Output in Gigabytes)

This option displays the result in gigabytes. The following is the command of its usage:

free -g

displaying the ram usage in gigabytes

5. Using ‘-t’ (Displaying Totals with the -t Option)

This option displays an additional line containing the total of the total, used and free columns.

free -t
free-t option

5. Using ‘-s’ and ‘-c’ (Continuously Monitoring Memory Usage)

This option allows you to display the output of free command after a set time gap given by the user. This option requires a numeric value to be passed with it that is treated as the number of seconds after which the output will be displayed.

free -s 3 -c 3
Usage of -s and -c options with free command

f

The above output will be displayed (only 3 times) after every 3 seconds. Now, with ‘-s’ you can only specify the time gap but not the number of times you want the output to be displayed.

For this, ‘-c’ is used along with ‘-s’ specifying the number of times the output will be displayed.

Importance of Linux ‘free’ Command

The following are the some of the important points of linux free commmand:

  • Real-time Memory Monitoring: It faiclitates with provides the immediate insight regarding the system memory usage. It helps the administrators and users in monitoring the resource allocation.
  • Performance Optimization: It llows the users for proactive management by identifying memory-intensive processes or applications, enabling timely adjustments to improve overall system performance.
  • Resource Planning: It facilitates with efficient resource planning and allocation decisions based on accurate data about available, used, and cached memory, ensuring optimal utilization of system resources.

Conclusion

The free command is used in Linux to check the amount of free and used memory on your system. It shows details about the RAM (physical memory) and swap space usage. The output displays different columns like total memory, used memory, free memory, and memory used for caching. You can use various options with free to change the units (bytes, kilobytes, etc.), show a continuous update of memory usage, or display totals. The free command is very useful for monitoring how much memory is available on your Linux system before running big programs or installing new applications.



Next Article
function command in Linux with examples

K

Kartik Thakral
Improve
Article Tags :
  • Linux-Unix
  • Technical Scripter
  • linux-command
  • Linux-misc-commands

Similar Reads

  • fc Command in Linux with Examples
    As we all know that LINUX is command friendly and while working on LINUX, you may deal with very long commands that may include long paths or really difficult syntax, and imagine what if working with such commands you do a minor mistake which will require re-writing of the entire command synopsis an
    3 min read
  • fc-cache command in Linux with Examples
    The fc-cache command in Linux scans the font directories and build font cache for applications which use fontconfig for their font handling. When no arguments are passed fc-cache scans each directory for font files readable by FreeType. A cache is created which contains properties of each font and t
    2 min read
  • fc-list command in Linux with examples
    fc-list command is a part of the fontconfig system. It is used to list the available fonts and font styles. Using the format option, the list of all fonts can be filtered and sorted out. Moreover, multiple parameters can be passed to it after a colon symbol (:) to restrict the information that is be
    3 min read
  • fdisk command in Linux with examples
    The 'fdisk' command in Linux, short for "format disk," is a powerful, dialog-driven utility used for creating and manipulating the disk partition table. Essential for system administrators and users looking to manage their hard drive’s structure, 'fdisk' supports a range of operations such as creati
    5 min read
  • fg command in Linux with examples
    The fg command in Linux is used to bring a background job into the foreground. It allows you to resume a suspended job or a background process directly in the terminal window, so you can interact with it. Syntaxfg [job_spec]The job_spec is a way to refer to the background jobs that are currently run
    3 min read
  • fgrep command in Linux with examples
    The 'fgrep' filter is used to search for the fixed-character strings in a file. There can be multiple files also to be searched. This command is useful when you need to search for strings that contain lots of regular expression metacharacters, such as "^", "$", etc. This makes 'fgrep' particularly v
    4 min read
  • file command in Linux with examples
    The 'file' command in Linux is a vital utility for determining the type of a file. It identifies file types by examining their content rather than their file extensions, making it an indispensable tool for users who work with various file formats. The file type can be displayed in a human-readable f
    3 min read
  • How to Find a File in Linux | Find Command
    Linux, renowned for its robust command-line interface, provides a suite of powerful tools for efficient file and directory management. Among these, the "find" command stands out as an indispensable asset, offering unparalleled versatility in searching for files based on diverse criteria. This articl
    10 min read
  • Finger command in Linux with Examples
    The 'finger' command is a powerful utility in Linux used to display information about users logged into the system. This command is commonly used by system administrators to retrieve detailed user information, including login name, full name, idle time, login time, and sometimes the user's email add
    4 min read
  • fmt command in Linux with examples
    fmt command in LINUX actually works as a formatter for simplifying and optimizing text files. Formatting of text files can also be done manually, but it can be really time-consuming when it comes to large text files, this is where fmt comes to rescue. fmt re-formats each paragraph in the file specif
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences