Linux comes with different command to check memory usage. free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.
vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity.
Then you can use top command which provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.
free command
Display free memory size in MB:
$ free -mOutput:
total used free shared buffers cached Mem: 750 625 125 0 35 335 -/+ buffers/cache: 254 496 Swap: 956 0 956
Displays a line containing the totals memory in MB:
$ free -t -m
Output:
total used free shared buffers cached Mem: 750 625 125 0 35 335 -/+ buffers/cache: 253 496 Swap: 956 0 956 Total: 1707 625 1082
vmstat command
Type vmstat command at shell prompt:
$ vmstatOutput:
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 1 0 0 131620 35432 341496 0 0 42 82 737 1364 15 3 81 1
top command
Type top command at shell prompt:
$ topTo exit from top command type q key.
Read man page of free, vmstat, top command for complete information.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- My 10 UNIX Command Line Mistakes
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email FAQ to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: 12/7/07


{ 19 comments… read them below or add one }
Hi ,
I need a unix command to get the total memory usage percentage.so that i can call this command from java.The output of the command should only be the percentage of memory utilization.
thanks
Suresh
Try:
ps aux | awk ‘{sum +=$4}; END {print sum}’
Bye!
Using the command free, vmstat, top all shows it uses almost 100% of the memory. But if I use the system monitor, it will show only less than 10%.
I am using CentOS 5. can anyone explain why the free, vmstat, top all displaying wrong information? Thanks.
$ free -m
total used free shared buffers cached
Mem: 3792 3638 154 0 128 3231
-/+ buffers/cache: 277 3515
Swap: 1983 0 1983
$ vmstat
procs ———–memory———- —swap– —–io—- –system– —–cpu——
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 108 158380 131948 3309388 0 0 106 75 203 180 0 0 98 1 0
Actualy memory is not used by application, but it is used for disk caching.
If memory is not fully utilized by kernel than it is wasted, by keeping data in cache when an application needs data again it can be provided faster.
If you want to see the memory from the perspective of application you should look at +- buffers/cache line, the free column of this line shows you the memory that can be used for applications.
In the case below my application using 2GB of memory.
# free -m
total used free shared buffers cached
Mem: 7973 7323 650 0 128 5152
-/+ buffers/cache: 2042 5931
Swap: 8189 40 8149
Hi ,
I take care 2000 PCs that using Redhat 7.3. I’m finding the command to create script file to check RAMBus of the PCs. Could you please help to recommend the appropriate one ?
Thanks.
Regard,
is there any way/script to find out physcial memory usage exclusive of buffer/cache usage??
very good
thanks
Regard,
You can also check memroy by using command “cat /proc/meminfo” it will give you detail info.
the memory information is also stored in /proc/meminfo… so just in case you don’t have any tools installed… cat /proc/meminfo
hi all
I use sun servers and solaris os and memory load has been increased to 90%
I need to know which command can i use to check on its memory and how i know the abnormal increase
hi all
I am trying to get the output of the command top in java using a processbuilder. But its not giving any output. Though a command such as ‘ps -all’ is giving the required output. Can anyone help please. Its urgent…
Thanks
How can I find the memory used by each php script on the server?
hi this is kishore
with single command can we get information of version of linux , ram,and memory status informationa. And as well as with single command the total system information
can i know the comman of linux
Regards
kishore
[kishore] You need to write a script which excutes various commands and output as a single command.
ps aux | awk ‘{sum +=$4}; END {print sum}’. It works.
Thanks Matt…
Is there any way to do the same for SWAP also.
How can get the average memory usage of a perl script that I am running on a linux machine? Can anybody help?
Hi kishore
Use this coomand to get all the required information
lsb_release -a && free -m
Believe that we have a memory leak on RHEL 4.5 with Java & Apache running.
ps -eo pid,ppid,rss,size,vsize,sz,pmem,comm | awk '{ rss += $3; size += $4; vsize += $5; sz += $6; pmem += $7} ; END { print "rss = "rss" size = "size" vsize = "vsize" sz = "sz" pmem = "pmem }' ; free -mrss = 4590060 size = 7302928 vsize = 11360544 pmem = 26.7
total used free shared buffers cached
Mem: 16028 15979 48 0 0 24
-/+ buffers/cache: 15954 73
Swap: 32767 4571 28196
Does anyone have a command, code, or program to identify where the memory is being utilized?
After a reboot the server is using 24.6% of memory or free shows 4869 MiB.
Thanks.
Hi Paul,
ps -auxf | sort -nr -k 4 | head -10
The above mentioned command will display top 10 memory usage in % by each process