Linux Archive Backup And Compress Utility | tar, gzip and bzip
Here I am going to explain you some of the backup/compression such as Archive Backup And Compress tools to collect multiple files and directories in Linux. As a Linux Administrator taking backup and restoring data is one of the regular and important tasks. To do this task in a most efficient way is that using tar, gzip, and bzip command line utility. So it’s important to know about the archiving/compression tools in Linux. In this article, I have provided some of the tools. Let’s have a look on the below steps for clear understand.
Suggestable Read: Part 2: Archive and Compress Tools
Also Read: Part 3: Compression and Archiving with zip, gzip, bzip2 and tar
The Linux “tar” stands for tape archive, which is used by a large number of Linux/Unix system administrators to deal with tape drives backup.
The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux.
The tar is most widely used the command to create compressed archive files and that can be moved easily from one disk to anther disk or machine to machine.
tar command examples including how to create archive files using (tar, tar.gz, and tar.bz2) compression, how to extract archive file, extract a single file, view content of the file, verify a file, add files or directories to an archive file, estimate the size of tar archive file, etc.
An Archive file is a collection of files or Directories stored in one file. Normally we use the tar command to archive the files in Linux. Tar (tape archive) command creates, appends, updates, lists and extract files to and from a single file.
We use different options with tar command to perform below operations as shown in below.
Creates an Archive file
Specifies the tarball
Appends files to the end of an existing tarball. Does not append to compressed tarballs.
Lists contents of a tarball
Appends files to the end of an existing tarball if the specified files are newer. Does not append
to compressed tarballs.
Verbose mode(to get real-time status of what command is doing)
Extarcts from the tarball
Includes (excludes) SELinux file contexts in archives.
Includes (excludes) extended file attributes in archives.
Let’s see how tar command will work and how to use with proper options:
1. Creating a tar file:
|[[email protected] ~] tar -cvf /tmp/etc.tar /etc|
The above command archives the contents of /etc/ directory to /tmp/etc.archive file location.
[[email protected] ~]# tar -cvf /tmp/etc.tar /etc
tar: Removing leading `/’ from member names
After creating a tar file or taking the back up of multiple files and directory, if you want to view the content inside of the .tar file. You need to run the command like below.
2. Listing out the archive file content: This command will give you the output of .tar file content.
|[[email protected] ~] tar -tvf /tmp/etc.tar|
[[email protected] tmp]# tar -tvf etc.tar
drwxr-xr-x root/root 0 2017-02-06 08:54 etc/
-rw-r–r– root/root 596 2017-01-08 19:50 etc/fstab
-rw——- root/root 0 2016-11-25 23:47 etc/crypttab
lrwxrwxrwx root/root 0 2016-11-25 23:47 etc/mtab -> /proc/self/mounts
drwxr-xr-x root/root 0 2016-11-25 23:50 etc/fonts/
drwxr-xr-x root/root 0 2016-11-25 23:59 etc/fonts/conf.d/
3. Extracting /tmp/etc.archive file:
|[[email protected] tmp] # tar -xvf /tmp/etc.archive|
Conclusion: I hope this Linux Archive Backup And Compression tools article will give you the good understand about Linux Archive Backup And Compress Utility and how to take backup and compressing the multiple files and directories using compression tools such as Gzip, Bzip2, Zip.