Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

How to Use Tar Command ?

The Linux tar command stands for tap archive, is not a compressed file and commonly called as a collection (which contains the contents of many files) of a single file.
Tar is the most commonly used command in Linux for creating a archive file. It saves multiple files, folders & other file formats (zip, gzip, bzip2 & tar) into a single archive file. Many of us very frequently uses three operations create, list & extract & two options file & verbose with tar to dealing the backups and restore.
Additionally we can use gzip & bzip2 commands for further compressing the tar archive. Mainly tar command used to performing backup (full and incremental) from the server by server administrator, other famous backup applications are using tar command for backup.
All the files and folders can be restore from the archive file whenever you want, every server administrator need to know the tar command and it’s usage for better backup solution.
By default tar command included into most of the distribution, so we can easily install from distribution official repository.
We are going to show you in this article, how we can use the tar command effectively for different purpose.
[Install Tar on RHEL/CentOS/Fedora]
$ sudo yum install tar

[Install Tar on Fedora] 22 and later]
$ sudo dnf install tar

[Install Tar on Debian/Linux Mint/Ubuntu]
$ sudo apt-get install tar

[Install Tar on openSUSE]
$ sudo zypper in tar

[Install Tar on Mageia]
$ sudo urpmi tar

[Install Tar on Arch based distro]
$ sudo pacman -S tar
Syntax : Common Syntax for tar command
Syntax : tar -[options] [/backup-location/backup-filename] /[webcontent-location]

Options : Commonly used options in tar command are listed below
  • z : Compress the backup file with ‘gzip’ to make it into small size.
  • c : Create a new backup archive
  • v : verbosely list files which are processed
  • p : Preserves the permissions of the files put in the archive for restoration later.
  • f : following is the archive file name
  • x : To extract a archive file
  • t : To viewing content of archive file
  • j : Archive the file with bzip2
  • r : To add new file or folder in existing archive file
  • W : To verify a archive file content
  • p : Compress the backup file with ‘present umask’.
  • C : To mention the path to extract the archive file
  • wildcards : Extract the group of file from archive file

1) How to create tar Archive File

The following example, backup the entire 2daygeek directory content into 2daygeek-backup-17-Dec-2013.tar file and store the backup file at /backup/site-backup/ directory.
# tar -cvf /backup/site-backup/2daygeek-backup-17-Dec-2013.tar /home/2daygeek
/home/2daygeek/
/home/2daygeek/etc/
/home/2daygeek/.bashrc
/home/2daygeekc/public_html/
/home/2daygeekc/public_html/captca/CaptchaSecurityImages.php
/home/2daygeekc/public_html/captca/form.php
/home/2daygeekc/public_html/captca/monofont.ttf
/home/2daygeekc/public_html/captca/error_log
/home/2daygeekc/public_html/colorlover.php
/home/2daygeekc/public_html/userfunctions.php
/home/2daygeekc/public_html/.htaccess

2) To create tar.gz Archive File

The following example, backup the entire 2daygeek directory content with .gzip compressed format (It uses z option which makes the tar into small size) into 2daygeek-backup-17-Dec-2013.tar.gz file and store the backup file at /backup/site-backup/ directory.
# tar -zcvf /backup/site-backup/2daygeek-backup-17-Dec-2013.tar.gz /home/2daygeek
/home/2daygeek/
/home/2daygeek/etc/
/home/2daygeek/.bashrc
/home/2daygeekc/public_html/
/home/2daygeekc/public_html/captca/CaptchaSecurityImages.php
/home/2daygeekc/public_html/captca/form.php
/home/2daygeekc/public_html/captca/monofont.ttf
/home/2daygeekc/public_html/captca/error_log
/home/2daygeekc/public_html/colorlover.php
/home/2daygeekc/public_html/userfunctions.php
/home/2daygeekc/public_html/.htaccess

Comments

Popular posts from this blog

PostgreSQL Pgbadger Installation On Linux

PostgreSQL Sequence

Postgresql maximum size

How to configure Replication Manager (repmgr) ?

PostgreSQL pgBadger