free Command in Linux with Examples

This tutorial explains Linux “free” command, options and its usage with examples.

free – display information about free and used memory on the system

DESCRIPTION

free displays the total amount of free and used physical memory and swap space in the system, as well as the buffers and cache consumed by the kernel.

SYNOPSIS

free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay ] [-c count ]

OPTIONS

Normal invocation of free does not require any options. The output, however, can be fine-tuned by specifying one or more of the following flags:

advertisement
advertisement

-b, –bytes
Display output in bytes.
-k, –kb
Display output in kilobytes (KB). This is the default.
-m, –mb
Display output in megabytes (MB).
-g, –gb
Display output in gigabytes (GB).
-l, –lowhigh
Display detailed information about low vs. high memory usage.
-o, –old
Use old format. Specifically, do not display -/+ buffers/cache.
-t, –total
Display total summary for physical memory + swap space.
-c n, –count=n
Display statistics n times, then exit. Used in conjunction with the -s flag. Default is to display only once, unless -s was specified, in which case default is to repeat until interrupted.
-s n, –repeat=n
Repeat, pausing every n seconds in-between.

EXAMPLES

1. Simple Example to display information about free and used memory on the system

$ free
             total       used       free     shared    buffers     cached
Mem:       1011876     896904     114972          0      43564     342528
-/+ buffers/cache:     510812     501064
Swap:      1046524      12756    1033768

2. To display memory usage in kilobytes

Note: Join free Sanfoundry classes at Telegram or Youtube
$ free -k
             total       used       free     shared    buffers     cached
Mem:       1011876     896904     114972          0      43580     342560
-/+ buffers/cache:     510764     501112
Swap:      1046524      12756    1033768

3. To display memory usage in megabytes

$ free -m
             total       used       free     shared    buffers     cached
Mem:           988        875        112          0         42        334
-/+ buffers/cache:        498        489
Swap:         1021         12       1009

4. Display memory information twice after delay of 1 second

advertisement
$ free -s 1 -c 2
             total       used       free     shared    buffers     cached
Mem:       1011876     897400     114476          0      43836     342668
-/+ buffers/cache:     510896     500980
Swap:      1046524      12756    1033768
 
             total       used       free     shared    buffers     cached
Mem:       1011876     897540     114336          0      43836     342648
-/+ buffers/cache:     511056     500820
Swap:      1046524      12756    1033768

5. Display total values too

$ free -t
             total       used       free     shared    buffers     cached
Mem:       1011876     897368     114508          0      43880     342648
-/+ buffers/cache:     510840     501036
Swap:      1046524      12756    1033768
Total:     2058400     910124    1148276

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

advertisement
If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.