Tag Archives: command

Linux : how to read output parse from “free” command

for example :

[myapit@linuxserver ~]$ free -m
             total  used  free  shared  buffers  cached
Mem:         7872   7732  139   0       1478     4346
-/+ buffers/cache:  1907  5964
Swap:        4095   45    4050

from the output above, we can get :-

First Line :

  • 7872 – total physical RAM size
  • 7732 – total RAM used include buffers and cached
  • 139 – total free RAM to be used by new process
  • 0 – shared memory, obsolete (not use anymore)
  • 1478 – total RAM buffered by applications
  • 4346 – total RAM used as cached by applications

Second Line:

-/+ buffers/cache:  1907  5964

What is the difference between buffers and Cache?
A buffer is a temporary location to store data for a particular application and this data is not used by any other application. This is similar to bandwidth concept. When you try to send burst of data through network, if your network card is capable of sending less data, it will keep these huge amounts of data in buffer so that it can send data constantly in lesser speeds. In other hand Cache is a memory location to store frequently used data for faster access. Other difference between a buffer and a cache is that cache can be used multiple times where as buffer is used single time. And both are temporary store for your data processing.

 

Third Line: -linux swap
Swap:        4095   45    4050

:: calculation to get the actual used and free ram
 Used RAM = 7732 - from first line
 Used Buffer = 1478 - from first line
 Used Cached = 4346 - from first line
Actual total used RAM = 7732 - (1478+4346) = 1908
Total available RAM = 7872 - 1908 = 5964

based on calculation above, in my opinion, we can use information from Second Line to get the actual used and free ram as the value after calculation seems to be the same

 


Reference:


http://www.linuxnix.com/2013/05/find-ram-size-in-linuxunix.html
http://unix.stackexchange.com/questions/152299/how-to-get-memory-usedram-used-using-linux-command

Advertisements

Linux : frequently used command

my frequently used linux’s command :-

1. Rename file.. replace space to dash ‘-‘
# rename ' ' '_' *

2. List file size in folder and sort
# du -sh * | sort -h

3. Log reading .. continuously
# tail -f /var/log/apache/error.log | grep --line-buffered "mydomain.com"

4. Tar folder in one file ( need to add “z” -zcvf  if you want to compress it, by default it will not compress the folder)
# tar -cvf namaarkib.tar folder/

5.  Append string to existing file
# echo "teks yang perlu dimasukkan" | tee -a /opt/runbind.sh

6. Useful command to check server type (virtual or physical) and any other hardware information (like memory slot)
# dmidecode
# dmidecode | less
# dmidecode -s system-product-name

7. Find contents of files.
# find . -type f -name "config.php" -exec grep -H "dbuser" {} \;
can manipulate -name and grep behavior . etc: -l to list file only

8. Netstat with wathch command.
# watch -n 30 "netstat -ntu | awk '{print \$5}' | cut -d: -f1 | sort | uniq -c | sort -n"
# watch -n 10 "netstat -ntp"
# netstat -c
monitoring withou filter but continuous
use "watch" for looping + filter