Connect with us

Hi, what are you looking for?

Linux

Linux TAR Commands with Examples for CentOS 7

What is TAR?

Tar (Tape archive) allows you to very easily, safely backup in Linux. If you have a small data to backing up it’s not a big deal. But if you want to backup large amount of data, yup it’s also easy but it’s take some time but not a big deal.

Backup Files Using TAR Archive

The first thing you need to do is type a command tar and we can take a backup. But there are some options we require to backup using tar, so we’ll discuss it firstly.
*** tar -option destination file source file

[root@techbrown]#  tar  -cvpf   /etc.tar   /etc
[root@techbrown ~]# ls   /
 bin     dev      file.txt  lost+found  opt   sbin     sys  var
 boot    etc      home      media       proc  selinux  tmp
 cgroup  etc.tar  lib       mnt         root  srv      usr

c -> create or override a backup file.
v -> Verbose (tell you what is going on during this process).
p -> preserving permission ( it is useful, if you are creating backups of web server and don’t put lowercase p, tar will not take it and we will face some problem while recovering data regarding permission. So after that recovery you need to go back and set permission and all that stuff once again. So keep this in mind that putp while taking backups.)
f -> Lowercase f is allow you to give tar a file name to create backup.
/etc.tar -> File name were you want to backup you data.
/etc -> The original data.

[root@techbrown]# du   -sh  /etc
To check the size of a file.
[root@techbrown]# file  /etc

To check the file system of a file.
And now to compress file nearly about 70% to compress already compress file, there we use some tools, these are following,

  1. gzip
  2. bzip2
  3. gzip
[root@techbrown]# gzip   /etc.tar
[root@techbrown ~]# ls /
 bin     dev         file.txt  lost+found  opt   sbin     sys  var
 boot    etc         home      media       proc  selinux  tmp
 cgroup  etc.tar.gz  lib       mnt         root  srv      usr
To unzip gzip compression
[root@techbrown ~]# gunzip  /etc.tar.gz
bzip
[root@techbrown ~]# bzip2  /etc.tar
[root@techbrown ~]# ls  /
[root@techbrown ~]# du  -sh  /etc.tar.bz2

Powerful than gzip.

To unzip bzip2 compression
[root@techbrown ~]# bunzip2   /etc.tar.bz2
To extract TAR
[root@techbrown ~]# tar  -xvf  /etc.tar
[root@techbrown ~]# tar  -xvf  /etc.tar  -C  /root

x-> To extract.
C-> Destination folder

Advertisement. Scroll to continue reading.
[root@techbrown ~]# ls root
To check file without extraction.
[root@techbrown ~]# tar  -tvf   /etc.tar

t-> List file in /etc.tar

Bzip and Gzip using TAR
[root@techbrown ~]# tar  -cvpzf   /sbin.tar.gz
[root@techbrown ~]# tar   -cvpjf   /bin.tar.bz2  /bin
To extract
[root@techbrown ~]# tar   -xvf  /bin.tar.bz

Congratulations your Backup files are saved on TAR Archives.

Comments
Advertisement
Advertisement

Linux

In this tutorial we will configure ISCSI Target Server on CentOS 8 / RHEL 8. ISCSI stands for Internet Small Computer Systems Interface.  This...

Linux

In this tutorial we will configure SELinux Modes on CentOS 8 / RHEL 8. SELinux stands for Security-Enhanced Linux and it is developed by...

Linux

DNF stands Dandified YUM and this is the default package manager for RHEL 8 / CentOS 8.  This tutorial explains you how to create...

Linux

If you forget a root password of your RHEL 8 and CentOS 8 and want to reset the password so that the RHEL 8...

Windows

How to auto upgrade JioFi firmware for JioFi 2 / JioFi 3 / JioFi 4 / JioFi 5 / JioFi 6 and other JioFi...

Advertisement

You May Also Like

Windows

How to auto upgrade JioFi firmware for JioFi 2 / JioFi 3 / JioFi 4 / JioFi 5 / JioFi 6 and other JioFi...

Windows

Internet is the most important public network for connecting to the WEB. For internet connection requirement the ISP is required as well as it...

Windows

How to download and install the Mobile Intel 4 Series Express Chipset Graphics Drivers for Windows 10.  Windows 10 is the one of the...

Windows

How to Install and Configure PCSX2 on Windows 10. The Windows 10 is the most recommended operating system for the Games. In stream platform...