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

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

MacOSX : cleaning download logs recorded by your mac

open your terminal and run this command to list what have you mac keep track of what you downloaded:

sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* ‘select LSQuarantineDataURLString from LSQuarantineEvent’

to delete those list, tun this command 

sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* ‘delete from LSQuarantineEvent’

you can check whether it is cleaned or not by running the first command

Linux : read write permission for group and apache

Situation : I need a group of developers  and apache  to have reads/writes permission on a folder in /var/www/html/foldername

 

Solution :

  • create users and a group

    #useradd develone
    #useradd develtwo
    #groupadd developergroup
     
  • Append “apache” and 2 users to “developergroup”

    #usermod -a -G developergroup apache
    #usermod -a -G developergroup develone
    #usermod -a -G developergroup develtwo
     
  • Set ownership and gid to “foldername”

    #chown apache:developergroup foldername
    #chmod 775 foldername
    #chmod g+s foldername

 

done. tested on CentOS 6.5 machine with ~50 users/developers

 

MySQL : drop table with prefix

SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) 
    AS statement FROM information_schema.tables 
    WHERE table_schema = 'nama_pengkalandata' AND table_name LIKE 'namaprefix_%';

run those SQL in mysq terminal or phpmyadmin or any mysql client. It will generate ‘drop table’ syntax.

ref: http://stackoverflow.com/questions/1589278/sql-deleting-tables-with-prefix

Installing module sybase_ct in CentOS 6.x with php 5.4

Firstly,  you may need to import/installl remi repos and development tools into your CentOS.

Then, install php,apache and freetds using yum :

#yum install httpd php freetds freetds-devel
#php -i (to identify php version installed)

Go to php.net and download the php souce code same version as above.
Extract it, and be prepare to compile the souce code.

#./configure –with-sybase-ct=shared,/usr
#make
# cp modules/sybase_ct.so /usr/lib64/php/modules
#cd /etc/php.d/
#vim sybase.ini

and enter the following text;

; Enable SAIBESSSS extension module
extension=sybase_ct.so

restart your apache, and create file contain <?php phpinfo(); ?> to check whether the module successfully installed or not. You also can check from terminal by running # php -i | grep sybase
Teston On CentOS 6.6 , PHP 5.4.38, Apache 2.2

Install and/or convert certificate (cert) in linux using openssl

Converting certificates between cer/pem/crt/der/pfx/p12 can be done in Linux with the use of OpenSSL tool via the terminal.

These commands allow you to convert certificates and keys to different formats to make them compatible with specific types of servers or software.

Convert a DER file (.crt .cer .der) to PEM

openssl x509 -inform der -in certificate.cer -out certificate.pem

Convert a PEM file to DER

openssl x509 -outform der -in certificate.pem -out certificate.der

Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM

openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

You can add -nocerts to only output the private key or add -nokeys to only output the certificates.

Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

 

Copy and paste from http://stackoverflow.com/questions/16583428/how-to-convert-an-ssl-certificate-in-linux for my personal reference only.