Using tar and gzip
Sometimes, we want to pack a full directory (including files) into a single file for backup purposes or to simply share it more easily. The command that can help aggregate files into one is tar
.
First, we need to install tar
:
[root@rhel-instance ~]# yum install tar -y
We can try by creating (as root
) a backup of the /etc
directory branch:
[root@rhel-instance ~]# tar -cf etc-backup.tar /etc tar: Removing leading '/' from member names [root@rhel-instance ~]# ls -lh etc-backup.tar -rw-r--r--. 1 root root 20M Feb 17 20:08 etc-backup.tar
Let's check the options used:
-c
: Short for create.tar
can put files together but also unpack them.-f
: Short for file. We specify that the next parameter will be working with a file.
We can try to unpack it:
[root@rhel-instance ~]# mkdir tmp [root@rhel-instance ~]# cd tmp/ [root@rhel-instance tmp]# tar -xf ../etc-backup.tar [root@rhel-instance tmp]# ls etc
Let’s check the...