Linux Check Memory Usage

Posted on in Categories last updated January 7, 2013

How do I check used and free RAM memory usage under Linux operating systems using command line and GUI tools?

Linux comes with different set of commands to check memory usage. The 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. The vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity. Finally, you can use the top, and/or atop/htop commands which provides a dynamic real-time view of a running system. top and friends can display system summary information as well as a list of tasks currently being managed by the Linux kernel.


The /proc/meminfo file stores statistics about memory usage on the Linux based system. The same file is used by free and other utilities to report the amount of free and used memory (both physical and swap) on the system as well as the shared memory and buffers used by the kernel.


Use the cat command or grep command to see /proc/meminfo file:
$ cat /proc/meminfo
$ less /proc/meminfo
$ more /proc/meminfo
$ egrep --color 'Mem|Cache|Swap' /proc/meminfo

Sample outputs:

MemTotal:        8120568 kB
MemFree:         2298932 kB
Cached:          1907240 kB
SwapCached:            0 kB
SwapTotal:      15859708 kB
SwapFree:       15859708 kB

free command

To display free memory size in MB (megabytes):
$ free -m
Sample outputs:

             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

       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

So how much free ram I have?

Type the following command:
$ free -m
Sample outputs:

Understanding Free Command Output
Understanding Free Command Output

In this above output, my server has used 2825 MB ram, and 9083 MB is available for other users and programs.

A list of free command options

  -b,-k,-m,-g show output in bytes, KB, MB, or GB
  -l show detailed low and high memory statistics
  -o use old format (no -/+buffers/cache line)
  -t display total for RAM + swap
  -s update every [delay] seconds
  -c update [count] times

vmstat command

Type the vmstat command at shell prompt:
$ vmstat
Sample outputs:

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 the shell prompt:
$ top
Sample outputs:

Fig.01: top command displaying used memory
Fig.01: top command displaying used memory

To exit from top command type q key.

atop command

The program atop is an interactive monitor to view the load on a Linux system. This program can display the amount of used and free memory. It is similar to top command but comes with additional advanced options. By default, the atop command is not installed on most Linux distributions.
$ atop
Sample outputs:

Fig.02: Linux Check Amount Of Memory With atop Command
Fig.02: Linux Check Amount Of Memory With atop Command

htop command

The program htop is an interactive process viewer. It is similar to top, but allows to scroll the list vertically and horizontally to see all processes and their full command lines.
By default, the htop command is not installed on most Linux distributions.
$ htop
Sample outputs:

Fig.03: Linux Check Amount Of Physical Memory With htop Command
Fig.03: Linux Check Amount Of Physical Memory With htop Command

GNOME Desktop: GUI tool to see memory usage

The “Gnome System Monitor” application enables you to display basic system information and monitor system processes, usage of system resources, and file systems. You can also use System Monitor to modify the behavior of your system. You can start System Monitor by visiting System menu > Choose Administration > System Monitor option. Or type the following command at the shell prompt:


Sample outputs:

Fig.04: Linux See Memory Usage With GUI System Monitor Tool
Fig.04: Linux See Memory Usage With GUI System Monitor Tool

Check out related media

(Video 01: Top five commands to see used and free memory under Linux)

A note about the performance

  1. RAM – An occupation percentage of 90% is considered as critical.
  2. SWAP – An occupation percentage of 80% is considered as critical.
  3. To solve performance related problems, add more RAM and increase the swap space (or move swap space to another disk controller).

Read man pages of free, vmstat, top, atop, and htop commands for more information.

80 comment

  1. Hi ,

    I need a unix command to get the total memory usage that i can call this command from java.The output of the command should only be the percentage of memory utilization.


  2. 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

  3. 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

  4. 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 ?



  5. the memory information is also stored in /proc/meminfo… so just in case you don’t have any tools installed… cat /proc/meminfo

    1. i am expecting a command to see memory information. you said cat /proc/meminfo ,it is for seeing the configuration file right… is there any possibility to get the details of memory directly..

  6. 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

  7. 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…


  8. 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


  9. ps aux | awk ‘{sum +=$4}; END {print sum}’. It works.
    Thanks Matt…
    Is there any way to do the same for SWAP also.

  10. How can get the average memory usage of a perl script that I am running on a linux machine? Can anybody help?

  11. 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 -m
    rss = 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.


  12. Hi Paul,

    ps -auxf | sort -nr -k 4 | head -10

    The above mentioned command will display top 10 memory usage in % by each process

    1. T Sudhakarraj, This is a great answer in order to see the top 10 application based on the percent usage but I thought I could help improve it a little. As you probably know, most hard core/old school bash programmers often object to using more commands then you need to get the output you want. When you are performing this command, it’s important to realize that the percentage shown is a reflection of the RSS size of that application and it does not consider RAM allocated by shared objects / dynamically linked libraries (I hate using that term since most people associate it with Windows DLL files but dynamically linked library, while the proper term in Windows is also the generic term to refer to these types of libraries / objects on any OS).

      Because the percentage of RAM shown in ps for any output that uses the %mem / pmem format specifier is in direct correlation with host much data that application has in RSS relative to how much physical ram the host has, you can sort the ouput in ps yourself by using the `–sort rss` option. The final command would look like:

      ps -A --sort -rss -o comm,pmem | head -n 11

      The output would look like:

      COMMAND         %MEM
      kvm              5.6
      thunderbird-bin  3.0
      java             2.4

      This will give you the 10 processes using the most ram ( I only showed 3 in my example) as well as the ps header describing each field. If you want to remove the header then you can add the option “–no-headers” (without the qyuotes) to ps. If you remove the headers in ps, you will probably want to change the head command to use 10 instead of 11 since the extra line is for the headers Also this example only shows the “short” command name or basically it only shows the command but non of the arguments. It also doesn’t show the actual amount of RSS being used. If you want to show the “long” command or basically the command name with all the arguments, replace “comm” with “cmd” in the ps options. If you want to display the actual amount of RSS being used by each app in the top 10 list, replace “comm,pmem” with “comm,pmem,rss” and it will now have three columns for command, percent of memory and kilobytes of RSS used instead of just command and percent of memory.

      Also, unfortunately ps doesn’t have the option to convert kilobytes to megabytes. This can still be displayed but it requires a bit more of a complex answer. In order to display the RSS usage in megabytes instead of kilobytes we run through a loop and do the math ourselves on each line.

      while read command percent rss; do if [[ "${command}" != "COMMAND" ]]; then rss="$(bc <<< "scale=2;${rss}/1024")"; fi; printf "%-26s%-8s%s\n" "${command}" "${percent}" "${rss}"; done < <(ps -A --sort -rss -o comm,pmem,rss | head -n 11)

      The example below calculates the megabytes used by each applications RSS rounded to nearest 100th of a whole number. You can change this to show more or less places after the decimal by changing "scale=2" to whatever number you like.

      Hope this helps some people.

      P.S.: I saw that the term RSS was used by someone before me but I don't see anywhere on this thread where anyone has defined it. RSS as it relates to RAM (on any OS as far as I know) is the portion of memory that a process is using that is held in RAM. Every process has RSS and RSS does not include any items in RAM which have been swapped to disk or are otherwise anywhere else then in the physical RAM. This means that the size of each programs RSS is the amount of data that program itself is storing in physical RAM.

  13. Actualy memory is not used by application | swap file memory is 1534196 and uses 0
    so pleas solution


  14. Hi All,
    We use a hospital Information system application. From 10:30 AM the performance becomes really slow and the application freezes. Not sure if it is due too many sessions open or number of client connections or cpu/memory issue.
    We have the application installed on all client machines. The application server running on RHEL 5.2 version on IBM Balde work stations with 2 node cluster. App server is connected to Oracle 11g Db server.
    Currently, we restart the the application server every 2 days after working hours and see that the performance back to normal. But if we do not restart the servers, the performance is bad again.
    Please let me know what all things I need to check here so to know what is causing the performance issue.


  15. cyberciti has been my partner since we had linux servers in the office, thank you and hope you will continue this site and more power to the webmaster and all its staff.

  16. Hey guys,

    i see my sites apache uses more memory around 4G, after restarting it release 3G.

    The actual problem is Apache keeps increasing its memory usage.

    Do you guys know how to overcome this issue.

    Thank You

  17. hi guys.
    The top 10 application are using 0% mem for ME …but top says..

    Mem: 4145948k total, 2776936k used, 1369012k free, 146512k buffers
    Swap: 1558296k total, 4k used, 1558292k free, 2467592k cached

    out of 4G ram 2.6 is already used..WIll the kernel allocate if a process require more than the free memory. Wat process is actually using the used one .??

    kindly help me with this.

    n 11id:/localdisk/lattice/lattice_36041# ps -A –sort -rss -o comm,pmem | head
    ntpd 0.0
    named 0.0
    vim 0.0
    bash 0.0
    sshd 0.0
    sshd 0.0
    sshd 0.0
    sshd 0.0
    bash 0.0
    sshd 0.0

    1. I see your using the command I mentioned above but with one less item in the head command output but that’s alright ;)

      You can show the same data, without limiting the input but also displaying the RSS usage (and the pid) for each process by running:

      ps -A –sort -rss -o pid,comm,pmem,rss

      The far right column will show you the RSS usage in kilobytes. The order is descending so the application with the highest allocated RSS (using the most) is at the top of the list. The application with the lowest allocated RSS (using the least) is at the bottom of the list. Remember that RSS is only referring to the memory you application is using that is actually in RAM and does not include anything swapped to disk so this is in fact the amount of RAM your application is using.

      Something important though that you may not have realized is that Linux tends to use almost all available memory whenever it can by default. Linux will leave an percent free (I don’t know how to check what the percent is but it doesn’t matter) and then it will allocate the rest to buffers and cache. The general idea is this, buffers is the smaller segment it allocates for I/O usage of processes that are running. This mostly refers to items that programs need to write to a disk but that data is often cached in memory and then written. This causes programs not to have to wait for I/O to complete and the kernel is then able to write the data to disk as quickly as it’s capable of doing but at the same time without having to have a program and hence the user wait for the information to be written to disk. The buffers are also used for IPC or inter process communication. The cache is mostly used for reading files off disk. The algorithm is uses, while complex, basically stores a combination of files that are popular and recent in cache memory. This speeds up disk read times a lot too. You will notice that the cache is almost always significantly larger then the buffers. You can view both of these using free to see total, used and free memory. You can use free -m for megabytes and free -g for gigabytes.

      This RAM, more quickly with cache then buffers, can be very quickly (on both) be released and therefor given to any process asking for RAM. This means that, although this RAM is used and it is used in way that speeds up your system, if any task needs the RAM, it will instantly be given to that process. One example would be if I start VLC movie player and VLC needs and therefor requests 50MB to run, then the kernel will free 50MB from cache and buffers and allocate it to VLC. This is why there is also a line when you run free which says “-/+ buffers/cache”. This line which shows numbers under used and free, isn’t the RAM you literally have used and literally have free because of ram allocated to cache and buffers, however it is the line you should refer to when you want to see how much free RAM you have because RAM allocated to buffers and cache will be instantly released and given to a process whenever it needs it.

      When you view your free memory inside top, it shows you the literally used RAM and literally free RAM meaning cache and buffers are added to used and subtracted from free and their is nothing wrong with this but the RAM inside cache and buffers is still available to you when you need it. As I mentioned, the best way to really see how much used and free RAM you have is to look at the “-/+ buffers/cache” line inside free. That line is there for a reason.

      Hope this helps.

      1. Ah I forgot that the forum breaks double hyphens by default (poor mans attempt to stop SQL injections maybe?). The actual command I have up top is

        ps -A --sort -rss -o pid,comm,pmem,rss

        Notice the double hyphens in front of sort.

    2. #################################################################
      # Developed by Ashok Kumar
      # 1:50 PM Monday, February 04, 2008
      TOT=`cat /proc/meminfo | grep MemTotal: | awk '{print $2}'`
      USED=`cat /proc/meminfo | grep Active: | awk '{print $2}'`
      FREE=$[$TOT - $USED ]
      echo > $LOG
      if [ "$USED" -gt "0" ]; then
         USEDPERC=$[$USED * 100 / $TOT]
         echo "Used Percentage      : $USEDPERC %"
         TOTMB=$[$TOT / 1024 ]
         USEDMB=$[$USED / 1024 ]
         FREEMB=$[$TOTMB - $USEDMB ]
         #echo "Used Percentage : $USEDPERC"
         if [ "$USEDPERC" -gt "80" ]; then
           echo "------------------------------------------------------------------" >> $LOG
           echo `hostname`   >> $LOG
           echo "------------------------------------------------------------------" >> $LOG
           echo "Total Memory (MB)    : $TOTMB" >> $LOG
           echo "Used Memory (MB)     : $USEDMB" >> $LOG
           echo "Free Memory (MB)     : $FREEMB" >> $LOG
           echo "Used Percentage      : $USEDPERC %"  >> $LOG
           echo "------------------------------------------------------------------" >> $LOG
           if [ "$USEDPERC" -gt "95" ]; then
      if [ "$FREEMB" -eq "0" ]; then
         echo "------------------------------------------------------------------" >> $LOG
         echo "    No free memory available in " `hostname`    >>$LOG
         echo "------------------------------------------------------------------" >> $LOG
  18. “jetole
    Hope this helps.”

    Thanks a lot boss , great explanation . is of great help to me as i am able to free up my mem , used by so many ssh process :)

  19. riyan,

    Yes and no. Generally speaking, Linux the kernel doesn’t do any real auditing / logging of memory usage but then again it shouldn’t either since Linux really is only a kernel so you will need to install another tool to deal with this. The most common / popular / recommended tool for this would be sysstat / sar and on quite a few distros (Debian, Ubuntu, CentOS), sysstat is the literal name of the package you want to install. Once installed, it will start logging the data but their really is no way for it to record data from before it was installed so basically, if you don’t have a audting / logging application like sysstat already installed then you can’t really view the past history until after it is.

  20. you can try from the terminal
    cat /proc/meminfo
    cat /proc/cpuinfo
    This will give you information regarding the memory and CPU

  21. Hi Im new to linux and have an older acer 340t travel mate i went into BIOS but didnt see how much memory i have..How to i get into where i can type commands to fine out how much memory It has and what would the command be. Thank you so much for your help

  22. MemUsed = MemTotal – MemFree – Buffers – Cached

    We can take the values from /proc/meminfo and calculate this;
    and can verify with gnome-system-monitor output.

  23. Then, you have to use RRD.
    1) create an RRD (database) for CPU and memory utilization using rrdtool. You can also write a script to do that using perl or python. In perl you can use (RRDs::create).

    2) Update the RRD with cpu and memory details periodically (on every 5-mints or hour)

    3) Use rrdtool xport / rrdtool graph command to get details of a specific period (hour/day/week/month/year)

    1. Timothy,

      That’s rather crude. You don’t need to program anything to get these stats nor do you need to write RRD scripts. One method that has been used by many system administrators for a long time is through sysstat though this is all console based. If you prefer a web based GUI with RRD graphs then cacti is already programmed to monitor all of this for you. There are also probably several dozen other ways to do this so you probably shouldn’t use terms like “Then, you have to use RRD”. Because you only know one way to do it doesn’t mean it’s the only way and you shouldn’t be dismissive.

      P.S.: You’re explanation seems to be lacking lacking a lot and the first thing I notice is how often you update the RRD is based on how often you have configured and RRD to be updated. An RRD database designed to be updated every 5 minutes would be pretty much useless if you update it every hour based on the way RRD is designed to implement this data. A better approach is to log this data (at least) twice as often you want it to be available, for example, if you want a daily bar graph of cpu usage with 48 points of input from data collected every 1/2 hour then log the data at least every 15 minutes. When you are you want to view this data then you dynamically create the RRD based on the the specifications you supply at the time and this way you are not bound to one poorly designed RRD component which you may have implemented ‘a long time ago” and now you are forced to use it even though you need statistics at an entirely different rate then what you had originally planned “way back when”

  24. One more P.S.: I use sysstat, cacti, munin and more to monitor the server farm I am responsible for. They all provide the same details in a general sense but in a detailed sense they are all different from one another in a way that one doesn’t entirely replace the other and I feel it’s best to implement whatever provides you with the details you need in a useful and efficient manner and if this means you have to use more then one tool for different ways to comprehend the data then there is nothing wrong with that. This isn’t Windows where you have to worry about product cost, contract lock in’s and vendor abuse so install 10 products if you need it and if you decide to install 20 just to see which ones ultimately give you the info that you need then there is nothing stopping you (at least not for most Linux tools. I can’t speak for all of them).

  25. Hi ,

    I have problem in one linux application server where 3 instaces is running of java, each instaces is alocated 1 gb memory but my server is using my 21 gb memory , i am surprised for this.

    Can anyone help me , i checked with many command but nothing found….

    Thanx in advance….

  26. Any ideea why on a CentOS 5.7 Final linux box, 64 bit version, my system only recognized 3261 MB RAM instead of 4 GB installed? When it boots and also in BIOS all 4 GB ram are shown, but under linux I only see 3,2 GB. Thanks!

  27. I recently discovered “htop”. This is a really nice tool to see your resources being used via your terminal and even offers point and click functionality!

    On Redhat-based systems simply type:
    # yum install -y htop

    Then from the command-line run:
    # htop

  28. Nirav,

    free (-k -m or -g for showing in kilo, mega or gigabytes) for memory usage
    iostat for disk io. Should be part of the systat package

  29. Hello all,

    Please let me know when i run command free -m on any linux box with 8GB assign ram it show me 7873 MB please let me know is linux kernel reserved any memory or where is 319 mb memory is use.

  30. hi sir
    Iam using linux os in friendlyARM
    I am having 64 MB of ram so it is using 64 MB but i want to limit it, it
    means i want 100 kb memory for future usage so restrict 64 MB ram to
    (64MB-100KB) (shortly: don’t use last 100 KB ram)
    command to overcome with program consuming too much RAM
    how it can be done ….can any one suggest me

  31. Anyone know how to find out what type of ram the server uses and how many sticks by command with Linux 6?

    For example my server has 4 gigs of ram, I am trying to find out if it has 4 1gb sticks or two 2gb sticks.

    Also I am trying to find what kind of ram, for example if it’s ddr3 1600


    1. dmidecode -t 17

      Handle 0x0021, DMI type 17, 34 bytes
      Memory Device
      Array Handle: 0x0009
      Error Information Handle: Not Provided
      Total Width: 72 bits
      Data Width: 64 bits
      Size: 8192 MB
      Form Factor: DIMM
      Set: 21
      Locator: DIMM 24
      Bank Locator: Node 1 Bank 24
      Type: DDR3
      Type Detail: Registered (Buffered)
      Speed: 1600 MHz
      Manufacturer: Samsung
      Serial Number: 36378A02
      Asset Tag: Unknown
      Part Number: M393B1K70DH0-CK0
      Rank: 2
      Configured Clock Speed: 1600 MHz

  32. lshw. comes standard on many systems including debian, ubuntu. etc. Last time I looked at rhel, cent, etc you need to add a third party repo.

  33. Hey All,

    How do I get the memory usage details in last 5 hours ? or let’s say Last few hours?

    Please suggest.


  34. hi ALL,

    Am installing java,nosql,oep,weblogic i want to find how much useage taken by cpu for each tool and RAM and HDD for each tool


    ravi sankar.G

  35. Hi Team,
    Can you assist me to find earlier particular time(may be 2-3 hours before) what process caused more CPU/memory in linux servers ? Thanks in Advance

    With Regards,

  36. Hi guys

    > In this above output, my server has used 2825 MB ram, and 9083 MB is available for other users and programs.

    If Nixcraft run his illustrative sample above with free from procps-ng >= 3.3.10 at the same moment, he wouldn’t get the same available memory. One of them (i.e. `free` == 3.3.10, and Nixcraft ;)) is lying to us.

    I run the two (free versions, not Nixcraft ;)) on the same Arch machine at 1 minute from each, doing nothing else than `pacman -U procps-ng–VERSION.tar.xz). Here’s their output (“available” RAM is under ‘*’):

    $ free -V
    free from procps-ng 3.3.10

    ┌([email protected])─(0)─(09:59 sat. jul. 16)
    └──> [1][0]$ free -m
    total used free shared buff/cache available
    Mem: 7807 4445 458 477 2903 *2550*
    Swap: 4047 0 4047

    $ free -V
    free from procps-ng 3.3.9

    ┌([email protected])─(0)─(10:01 sat. jul. 16)
    └──> [1][0]$ free -m
    total used free shared buffers cached
    Mem: 7807 7350 456 474 221 2308
    -/+ buffers/cache: 4820 *2987*
    Swap: 4047 0 4047

    Guys, how much available RAM does this box have atm?
    The one who knows and can explain will get my respect + a mint tea / beer.

Leave a Comment