The free command is used to view how much memory (RAM) is available. The free command without any options will display the available memory in bytes.
~]# free
       total    used   free  shared  buffers  cached
Mem: Â Â Â 20453604 Â 19756444 Â 697160 Â Â Â 16 Â 189332 Â 3692964
-/+ buffers/cache: Â 15874148 Â 4579456
Swap: Â Â Â 2097148 Â Â 389432 Â 1707716
Typically, the -h (human readable) option is used to view the available memory as M (megabytes) and G (gigabytes). When contemplating "do I have enough memory", if you are on version 6 of Red Had, look at the "free" column and add up mem and buffers/cache. I ususally do not include swap in this calculation, since software may not perform as well on swap memory.
~]# free -h
       total    used   free  shared  buffers  cached
Mem: Â Â Â Â Â 19G Â Â Â 19G Â Â 510M Â Â Â 16K Â Â 185M Â Â 3.6G
-/+ buffers/cache: Â Â Â 15G Â Â 4.3G
Swap: Â Â Â Â 2.0G Â Â Â 380M Â Â 1.6G
When contemplating "do I have enough memory", if you are on version 7 of Red Had, look at "available".
~]# free -h
       total    used   free  shared  buff/cache available
Mem: Â Â Â Â Â 19G Â Â Â 19G Â Â 510M Â Â Â 16K Â Â 3.6G 8.0G
Swap: Â Â Â Â 2.0G Â Â Â 380M Â Â 1.6G
The following command can be used to display the top 10 processes using swap memory.
~]$ for file in /proc/*/status ; do egrep 'VmSwap|Name' $file | sed ':label; N; $! b label; s|\n| |g' | awk '{print $4 " " $5 " " $2}'; done | sort --numeric --reverse | head
296272 kB wdavdaemon
101292 kB wdavdaemon
82872 kB httpd
81860 kB httpd
81720 kB httpd
70932 kB wdavdaemon
64560 kB httpd
47700 kB httpd
46916 kB httpd
46160 kB httpd
Notice in the above example that numerous HTTPD processes are using swap. The following command can be used to display the amount of swap being used by the HTTPD processes.
~]$ for file in $( ls /proc/*/status ); do egrep '^(VmSwap|Name|Pid)' $file | sed ':label; N; $! b label; s|\n| |g' | awk '{print $6 " " $7 " " $2 " (PID " $4 ")"}'; done | sort --numeric --reverse | grep httpd
83968 kB httpd (PID 32287)
83080 kB httpd (PID 31545)
82476 kB httpd (PID 31621)
65488 kB httpd (PID 36144)
51836 kB httpd (PID 30379)
50920 kB httpd (PID 33691)
50460 kB httpd (PID 31813)
44676 kB httpd (PID 35054)
41372 kB httpd (PID 33760)
39396 kB httpd (PID 36338)
36280 kB httpd (PID 33107)