In this post, i will share with you on how to create the tar file and then gzip the file on Red Hat Enterprise Linux 6 (RHEL).
1. Create testing directory and create three sample files :
[root@rhel6 ~]# mkdir testing [root@rhel6 ~]# cd testing [root@rhel6 testing]# touch file1.txt [root@rhel6 testing]# touch file2.txt [root@rhel6 testing]# touch file3.txt [root@rhel6 testing]# ls file1.txt file2.txt file3.txt
2. Start to create a tar named testing.tar.gz in the directory you currently are in :
[root@rhel6 testing]# pwd /root/testing [root@rhel6 testing]# cd .. [root@rhel6 ~]# tar -czvf testing.tar.gz testing testing/ testing/file3.txt testing/file1.txt testing/file2.txt
Note : In the above example command the system would create a tar file named testing.tar.gz in the directory you currently are in. I added the .gz suffix to the archive file name, because the z flag tells tar to use the same compression as the gzip command.
c = create a new tar file
t = List the contents of an archive.
x = Extract the contents of an archive.
f = create the tar file with filename provided as the argument
M = The archive can span multiple floppies.
v = Print verbose output (list file names as they are processed).
u = Add files to the archive if they are newer than the copy in the tar file.
z = use gzip to zip it