How to find Linux distribution name and version?


unameSometimes we need to find out Linux distribution name and version of current installed Linux OS. Here is a tutorial addressing this problem.

There are three methods to find out Linux distribution and version:
1. /etc/*-release
2. lsb_release
3. /proc/version

Method 1: /etc/*-release

Issue following command to find out distro and version of installed Linux-

$ cat /etc/*-release

Sample output:

VERSION="13.10, Saucy Salamander"
PRETTY_NAME="Ubuntu 13.10"

Method 2: lsb_release

lsb in lsb_release stands for Linux Standard Base

$ lsb_release -a

Sample output:

No LSB modules are available.
Distributor ID: LinuxMint
Description: Linux Mint 16 Petra
Release: 16
Codename: petra

Method 3: /proc/version

This command returns kernel version and gcc version which was used to build it.

$ cat /proc/version

Sample output:

Linux version 3.11.0-12-generic (buildd@allspice) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu7) ) #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013

Another way to find kernel version:

This command returns kernel version of currently installed Linux OS.

$ uname -r


$ uname -mrs

Sample output:

Linux 3.11.0-12-generic x86_64

Thank you.

Backup your Linux remotely using rsync command

rsync is a command in Linux which stands for remote sync. It is used for backing up the data. It synchronizes the directories and files from one location to another in a good way. The backup destination could be either on local or on remote server.


  • Speed: rsync replicates all the data from source to destination and then it transfers only the changed blocks/bytes to the destination. This makes the transfer fast.
  • Security: It uses encryption using ssh technique.
  • Bandwidth: It compresses the block at source and then at the receiving end it decompresses the block. It transfers the data block by block using compression and decompression at source and destination side respectively. Hence uses less bandwidth.
  • Privileges: No extra privileges are required to use rsync.


$ rsync options source destination

Case 1: Synchronize two directories in local server

use rsync -zvr command (z to enable compression, v for verbose, r for recursive)

$ rsync -zvr /var/opt/installation/inventory/ /root/temp

The above command does not preserves the timestamp.

Case 2: Preserve timestamps using rsync -a

The -a options preserves symbolic links, permissions, timestamp, owner and group.

$ rsync -azv /var/opt/installation/inventory/ /root/temp/

Case 3: Synchronize only a single file

Specify the file name to the rsync command

$ rsync -v /var/lib/rpm/Pubkeys /root/temp/

Case 4: Synchronize files Local->Remote

$ rsync -avz /root/temp/ [email protected]:/home/chankey/temp/

Case 5: Synchronize files Remote->Local

$ rsync -avz [email protected]:/var/lib/rpm /root/temp

Case 6: Select remote shell

$ rsync -avz -e ssh [email protected]:/var/lib/rpm /root/temp

rsync -e ssh => uses the ssh shell for remote sync

Case 7: Do not overwrite modified file at destination

If the file at the destination is modified and if we don’t want to change it back to the old one again then using rsync -u option.

$ rsync -avzu [email protected]:/var/lib/rpm /root/temp

Case 8: Synchronize only the directory Tree structure (not files)

use rsync -d option for this purpose.

$ rsync -v -d [email protected]:/var/lib/ .

Case 9: Do not create new file at destination, just update existing files

use --existing option

$ rsync -avz --existing [email protected]:/var/lib/rpm/ .

Case 10: Transfer the entire file

use rsync -W option

#  rsync -avzW  [email protected]:/var/lib/rpm/ /root/temp

How to view contents of a file in Linux

view file in linux

You can use any of the method given below to view contents of a file in Linux. Let us say the file name is “filename”. Then you can view its content…

1. using cat command

cat filename


cat < filename

2. using head command

head filename

3. using tail command

tail filename

4. using pg command

pg filename

5. using more command

more filename

6. using paste command

paste filename

7. using grep command

grep '.*' filename

8. using cut command

cut -c 1- filename

9. using while loop

while read line
>echo $line
>done < filename

10. using xargs command

xargs -L1 < filename

11. using sed

sed '' filename


sed -n 'p' filename


sed -n '1, $p' filename

12. using awk

awk '1' filename


awk '{print;}' filename


awk '{print $0;}' filename

13. using perl

perl -pne '' filename


perl -ne 'print;' filename


perl -ne 'print $_;' filename

If you know some more ways then share them in comments.

A complete ffmpeg tutorial


ffmpeg is a very fast video and audio converter that can also grab from a live audio/video source. It can also convert between arbitrary sample rates and resize video on the fly with a high quality polyphase filter.

Installing ffmpeg

sudo apt-get install ffmpeg


Below are some tasks which you can perform using ffmpeg.

Getting information of a video

To get information of a video file use -i option as:

ffmpeg -i /path/videofile.avi

Making video from images

You can combine the images to make a video (like movie maker in windows) using ffmpeg as:

ffmpeg -f image2 -i image%d.jpg videofile.mpg

The above command will take all the images from the current directory (image1.jpg, image2.jpg, etc) and will join them to make a video file videofile.mpg.

Making images from video file

This is just opposite of the last step. This will take a video and will generate images from it.

ffmpeg -i videofile.mpg image%d.jpg

Encoding video for iPod/iPhone

Source file: s_videofile.avi
Audio codec: aac
Audio bitrate: 128 kb/s
Video codec: mpeg4
Video bitrate: 1200 kb/s
Video size: 320×180
Generated video: f_videofile.mp4

ffpmeg -i s_videofile.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200 kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320*180 -title X f_videofile.mp4

Encoding video for PSP

Source : s_videofile.avi
Audio codec : aac
Audio bitrate : 32 kb/s
Video codec : xvid
Video bitrate : 1200 kb/s
Video size : 320×180
Generated video : f_videofile.mp4

ffmpeg -i s_videofile.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac f_videofile.mp4

Video to Audio

You can extract the audio from a video file and save it as mp3 format.

ffmpeg -i s_videofile.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 soundfile.mp3

Source video : s_video.avi
Audio bitrate : 192kb/s
output format : mp3
Generated sound : soundfile.mp3

wav to mp3

ffmpeg -i s_audiofile.wav -acodec mp3 -ab 192k f_audiofile.mp3

avi to mpg

ffmpeg -i s_videofile.avi f_videofile.mpg

mpg to avi

ffmpeg -i s_videofile.mpg f_videofile.avi

avi to flv

ffmpeg -i s_videofile.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv f_videofile.flv

avi to dv

ffmpeg -i s_videofile.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 f_videofile.dv

avi to gif

ffmpeg -i s_videofile.avi f_giffile.gif

Mixing video with a sound file

ffmpeg -i s_audiofile.wav -i s_videofile.avi f_videofile.mpg

avi to mpeg (for dvd players)

ffmpeg -i s_videofile.avi -target pal-dvd -ps 2000000000 -aspect 16:9 f_videofile.mpeg

ps 2000000000 is the maximum size for the output file in bits hence it is 2 GB here.

Compress avi to divx

ffmpeg -i s_videofile.avi -s 320x240 -vcodec msmpeg4v2 f_videofile.avi

Compress Ogg Theora to mpeg dvd

ffmpeg -i s_videofile.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 f_videofile.mpg

Compress avi to SVCD mpeg2

NTSC format:

ffmpeg -i s_videofile.avi -target ntsc-svcd f_videofile.mpg

PAL format:

ffmpeg -i s_videofile.avi -target pal-svcd f_videofile.mpg

Compress avi to VCD mpeg2

NTSC format:

ffmpeg -i s_videofile.avi -target ntsc-vcd f_videofile.mpg

PAL format:

ffmpeg -i s_videofile.avi -target pal-vcd f_videofile.mpg

Multipass encoding

ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2

sudo command

sudo command

sudo command is required when executing a command with some other user’s permission. Other user can either be root or else. Why we need to execute command with root’s permission? There are some commands that do some change in the system which are dangerous and can bring the system down, only root has such permissions.

sudo command


One can also switch user via su command and then execute the desired command but sudo is much more secure than su. Commands (along with arguments) executed with sudo are logged in a file. For Red Hat distros, /var/log/secure saves all the logs and for debian based, its /var/log/auth.log.

The file /etc/sudoers can be edited for configuring sudo and giving privileges to individual users or group of users.

Setting up sudo

For an individual user

Syntax for allowing an individual user (here Ayush) is:

ayush ALL=(ALL) ALL

“ayush” here is username of the user you want to allow
“ALL” specifies that sudo is accessible from all terminals
“(ALL)” specifies all users
“ALL” for all commands

For a group

Entry in sudoers file goes like:

%linuxstall ALL=(ALL) ALL

“linuxstall” can be replaced by the name of group.

Execute commands as root

Once the sudoers file is all set, you can now execute commands as root. For an instance, mount command can only be executed by root, but things go well with sudo.

 sudo mount /dev/sda1 /mnt


Use sudo command on the fly while editing in vim

There are some files that only root can save (say /etc/group) but having sudo in hand, it can be done as follows:

sudo vim /etc/group

But, if you have opened the file as a normal user and wish to save but unable as only root can do that- sudo is your friend:

:w !sudo tee %

Above command will the save the file for you as a root even when you didn’t use it while opening. sudo just doesn’t mind!


If a user is not listed in sudoers file and tries to use sudo, admin will be notified by making a log entry and user will get following error:

<user> is not in the sudoers file. This incident will be reported.