How to Install & Configure VIM Editor in Linux

Step 1: Install VIM Package

Firstly, install the vim package:
For RedHat/Fedora/CentOS

# yum -y install vim vim-enhanced

For Debian/Ubuntu

# apt-get install vim

Step 2: Set the aliase

Set the aliase of vim command in /etc/profile file

# vi /etc/profile
alias vi='vim'

Step 3:Configure Vim

Edit following changes in ~/.vimrc in order to configure VIM Editor

# vi ~/.vimrc

" use extended function of vim (no compatible with vi)

set nocompatible
" specify encoding

set encoding=euc-jp
" specify file encoding

set fileencodings=iso-2022-jp,sjis
" specify file formats

set fileformats=unix,dos
" take backup

" if not, specify [ set nobackup ]

set backup
" specify backup directory

set backupdir=~/backup
" take 50 search histories

set history=50
" ignore Case

set ignorecase
" distinct Capital if you mix it in search words

set smartcase
" highlights matched words

" if not, specify [ set nohlsearch ]

set hlsearch
" use incremental search

" if not, specify [ set noincsearch ]

set incsearch
" show line number

" if not, specify [ set nonumber ]

set number
" Visualize break ( $ ) or tab ( ^I )

set list
" highlights parentheses

set showmatch
" show color display

" if not, specify [ syntax off ]

syntax on
" change colors for comments if it's set [ syntax on ]

highlight Comment ctermfg=LightCyan
" wrap lines

" if not, specify [ set nowrap ]

set wrap

How to Install wkhtmltopdf in Linux

Installation of wkhtmltopdf in CentOS/RedHat/Fedora

Step 1: Pre-Requisites

# yum install -y xorg-x11-fonts-75dpi
# yum install -y xorg-x11-fonts-Type1

For 64bits OS

# wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

For 32bits OS

# wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-i386.rpm

Step 1: Pre-Requisites

After the file has been downloaded, run the command:

For 64bits OS

# rpm -Uvh wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm

For 32bits OS

# rpm -Uvh wkhtmltox-0.12.2.1_linux-centos6-i386.rpm

Installation of wkhtmltopdf in Debian/Ubuntu

Step 1: Pre-Requisites

First we have to install the necessary libraries in order to install wkhtmltopdf package.

# sudo aptitude install openssl build-essential xorg libssl-dev

For 64bits OS

# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
# tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
# mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
# chmod +x /usr/local/bin/wkhtmltopdf

For 32bits OS

# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2
# tar xvjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
# mv wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
# chmod +x /usr/local/bin/wkhtmltopdf

How to Delete Buffers and Cache Memory in Linux

Step 1: Check Buffers & Cache Memory

To check the buffers and cache memory in linux, execute the following command:

# free
              total        used        free      shared  buff/cache   available
Mem:        1015944      211640       94724       57700      709580      562416
Swap:             0           0           0

Step 2: Check Buffers & Cache Memory

Now delete and check the buffers and cache memory it will be reduced:

# sync && echo 3 > /proc/sys/vm/drop_caches && free

Following are the Linux Kernal that how can we drop the various aspects of cached items by changing the numeric argument to the above command
To free pagecache:

# echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

# echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

# echo 3 > /proc/sys/vm/drop_caches

How to Create/delete Softlink & Hardlink

A link is nothing more than a way of matching two or more file names to the same set of file data.

How to create softlink

A soft link, or more common, a symlink, is link a shortcut to the targeted file or directory. So when is removed the original target stays present. This is the opposite of a hard link which is a reference to the target and so, if the hard link is removed, so is the target.

# ln -s /directory/ xymon

How to delete the softlink

#unlink xymon

How to create hardlink

Hard links are essentially a file with multiple names. Hard links share the same data blocks on the hard disk (have the same inode), while they continue to behave as independent files. If one of the hard links is deleted, the hard link count decreases by one. When all hard links are deleted, the data ceases to exist.

# ln -i /directory/file hardlink/file

How to delete the hardlink

#rm hardlink/file

How to Install ffmpeg package in Linux

Step 1: Prerequisites

In order to install ffmpeg package in linux first download the following libraries:

# wget ftp://rpmfind.net/linux/centos/6.5/os/x86_64/Packages/libdc1394-2.1.2-3.4.el6.x86_64.rpm
# yum -y localinstall libdc1394-2.1.2-3.4.el6.x86_64.rpm
# rpm -ivh http://dl.atrpms.net/el7-x86_64/atrpms/stable/atrpms-repo-7-7.el7.x86_64.rpm
# yum -y localinstall atrpms-repo-7-7.el7.x86_64.rpm

Step 2: Installation

RHEL/CentOS/Fedora

Now install ffmpeg package using the following command:

# yum -y install ffmpeg

Ubuntu/Debian

For Ubuntu and Debian Users execute the following command:

# apt-get update
# apt-get install ffmpeg

Step 3: Check Version

To check the current version of ffmpeg, execute the below command:

# ffmpeg -version

ffmpeg version 2.0.2
built on Oct 27 2013 11:21:04 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)

Logs in Linux

Introduction

Logs are very helpful while troubleshooting as it contains the relevant information whenever disaster appear on server or any service is not working properly. So these logs saves time in troubleshooting.

List logs

By default most Linux logs can be found in the directory /var/log/.

# ls -l /var/log
total 5756
drwxr-xr-x. 2 root root 4096 Feb 25 13:14 anaconda
drwxr-x---. 2 root root 94 Apr 20 20:16 audit
-rw-r--r--. 1 root root 0 Feb 25 13:13 boot.log
-rw-------. 1 root utmp 1808256 Apr 22 07:34 btmp
-rw-r--r--. 1 root root 1134 Apr 10 03:08 choose_repo.log
drwxr-xr-x. 2 chrony chrony 6 Feb 5 2014 chrony
-rw-r--r--. 1 root root 2534 Apr 10 03:08 cloud-init.log
-rw-r--r--. 1 root root 27149 Apr 22 07:01 cron
-rw-r--r--. 1 root root 24134 Apr 12 03:22 cron-20150412
-rw-r--r--. 1 root root 99515 Apr 20 03:43 cron-20150420
-rw-r--r--. 1 root root 32598 Apr 10 03:08 dmesg
-rw-------. 1 root root 2003 Apr 21 07:27 grubby
drwx------. 2 root root 4096 Apr 20 03:43 httpd
-rw-r--r--. 1 root root 292292 Apr 22 00:57 lastlog
-rw-------. 1 root root 0 Apr 20 03:43 maillog
-rw-------. 1 root root 198 Apr 10 03:08 maillog-20150412
-rw-------. 1 root root 1093 Apr 16 06:59 maillog-20150420
-rw-------. 1 root root 259933 Apr 22 07:32 messages
-rw-------. 1 root root 303675 Apr 12 03:22 messages-20150412
-rw-------. 1 root root 932940 Apr 20 03:43 messages-20150420
-rw-r-----. 1 mysql mysql 31400 Apr 22 01:30 mysqld.log
drwx------. 2 root root 6 Jan 26 2014 ppp
drwxr-xr-x. 2 root root 69 Apr 20 03:43 rhsm
-rw-------. 1 root root 313890 Apr 22 07:34 secure
-rw-------. 1 root root 584361 Apr 12 03:05 secure-20150412
-rw-------. 1 root root 1343433 Apr 20 03:35 secure-20150420
-rw-------. 1 root root 0 Apr 20 03:43 spooler
-rw-------. 1 root root 0 Feb 25 13:05 spooler-20150412
-rw-------. 1 root root 0 Apr 12 03:22 spooler-20150420
-rw-------. 1 root root 0 Feb 25 13:02 tallylog
drwxr-xr-x. 2 root root 22 Apr 10 03:08 tuned
-rw-rw-r--. 1 root utmp 9600 Apr 22 00:57 wtmp
-rw-------. 1 root root 6126 Apr 21 07:28 yum.log

Following are some important logs files in linux.

/var/log/audit/
/var/log/auth.log
/var/log/boot.log
/var/log/cron
/var/log/daemon.log
/var/log/dpkg.log
/var/log/messages
/var/log/dmesg
/var/log/kern.log
/var/log/lastlog
/var/log/maillog
/var/log/mail.log
/var/log/wtmp
/var/log/utmp
/var/log/faillog
/var/log/httpd/
/var/log/apache2
/var/log/user.log
/var/log/Xorg.x.log
/var/log/alternatives.log
/var/log/btmp
/var/log/cups
/var/log/anaconda.log
/var/log/yum.log
/var/log/lighttpd/
/var/log/conman/
/var/log/mail/
/var/log/prelink/
/var/log/sa/
/var/log/secure
/var/log/sssd
/var/log/samba/
/var/log/vsftpd/

Logwatch

To watch the run time logs execute the logwatch command:

# logwatch /path/of/log/file

Real Time Logs

To get all newly added lines from a log file in real time on the shell, use the command:

# tail -f /var/log/mail.log
# tail -f /var/log/vsftpd.log

How to Clean History in linux

Step 1: Check the History

In order to check the executed shell commands in linux, use the history command

# history
  366  cd ..
  367  make
  368  cd posix-local/
  369  cd app/
  370  less Makefile
  371  ls -l
  372  cd bin/

Step 2: Clear the History

To clear all your history, use

# history -c

To delete a single line, use

# history -d linenumber

How to Compress file/folder in Linux

Introduction

A backup, or the process of backing up, refers to the copying and archiving of computer data so it may be used to restore the original after a data loss event. The verb form is to back up in two words, whereas the noun is backup. Backups have two distinct purposes.

  • The primary purpose is to recover data after its loss, be it by data deletion or corruption.
  • Data loss can be a common experience of computer users.

Following are the methods through which we can compress the file and folders.

1) ZIP a file/folder

#zip file.zip file1 file2
#zip file.zip dir1
#zip -option file.zip dir1

How to zip a file with excluding file/folder

zip -r conference_01-01-2015_14-30.zip /var/www/conference/* -x home_backup/

2) TAR a file/folder

tar -cvf /backup/etc.tar /etc/*
tar -cvf /backup/etc.tar

3) GZIP a file/folder

gzip is the preferred compression tool for Linux. To compress the tar file using gzip, following is the command:

gzip etc.tar

To decompress the tar file using gzip, following is the command:

gzip -d etc.tar.gz

4) BZIP2 a file/folder

There is also another tool that is rapidly gaining acceptance in the Linux world: bzip2. This is supposed to become the official way of doing it in the near future, so it may be a good idea to get to know ‘bzip2’
To compress the tar file using bzip2, following is the command:

bzip2 etc.tar

To decompress the tar file using bzip2, following is the command:

bzip2 -d etc.tar.bz2

VIM Editor Commands

How to Check CPU Detailed Information

There are several ways in order to check the CPU detailed Information.

1) /proc/cpuinfo

The /proc/cpuinfo and sysfs stores info about your CPU architecture ike number of CPUs, threads, cores, sockets, NUMA nodes, information about CPU caches, CPU family, model, bogoMIPS, yte order and much more:

# less /proc/cpuinfo

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 62
model name      : Intel(R) Xeon(R) CPU E5-2695 v2 @ 2.40GHz
stepping        : 4
cpu MHz         : 2400.084
cache size      : 30720 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu de tsc msr pae cx8 sep cmov pat clflush mmx fxsr sse sse2 ss ht nx constant_tsc aperfmperf pni pclmulqdq ssse3 sse4_1 sse4_2 x2apic popcnt aes f16c rdrand hypervisor ida arat
bogomips        : 4800.16
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

2) nproc

The nproc command just prints out the number of processing units available. Note that the number of processing units might not always be the same as number of cores.

# nproc
2

3) getconf

The most simplest tool comes with glibc and is called getconf:

# getconf _NPROCESSORS_ONLN
2

4) lscpu

lscpu is a small and quick command that does not need any options. It would simply print the cpu hardware details in a user-friendly format.

# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 62
Model name:            Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
Stepping:              4
CPU MHz:               2494.094
BogoMIPS:              4988.18
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              25600K
NUMA node0 CPU(s):     0

5) dmidecode

The dmidecode command displays some information about the cpu, which includes the socket type, vendor name and various flags.

# dmidecode -t 4 | grep CPU
        Socket Designation: CPU1
        Version: Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
        Socket Designation: CPU2
        Version: Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz