How to Create the tar file then gzip the file on RHEL 6

Share this Article :

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 :

[[email protected] ~]# mkdir testing
[[email protected] ~]# cd testing
[[email protected] testing]# touch file1.txt
[[email protected] testing]# touch file2.txt
[[email protected] testing]# touch file3.txt
[[email protected] 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 :

[[email protected] testing]# pwd
/root/testing
[[email protected] testing]# cd ..
[[email protected] ~]# 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