Tar derived from tape archive is provides the ability to create tar archives to store files conveniently on magnetic tape.
To create tar file
# tar -cvf test.tar /etc
# tar cvf test.tar /etc
# tar cvf /backup/test.tar /boot/
To view contain of file
# tar -tvf test.tar
# tar tvf test.tar
To extract tar file
# tar -xvf test.tar
# tar xvf test.tar
-c ---> create
-v ---> verbose
-f ---> filename
To append in tar file
# tar --append --file=test.tar /root/test.txt
# tar --append --file=t.tar /root/install.log -P
To delete from tar file
# tar --delete --file=test.tar /root/test.txt
While deleting some files from exiting tar file make sure
you define the path of test (/root/test.txt) which it displays into output of
tar -tvf command
tar also use with compression tools like gzip, bzip2, or compress to save disk space as we do using WinZip and Winrar.
-:Compression Tools :-
# compress -v test.tar [To compress a file with an extension .Z]
# zcat -l test.tar.Z [To read compress data]
# zmore test.tar.Z [viewing of compressed text]
# uncompress -v test.tar.Z [To uncompress data]
# gzip -v test.tar [To compress a file with an extension .gz]
# gzip -l test.tar.gz [To read compress data]
# gunzip -v test.tar.gz [To uncompress data]
# zip -v test.tar.zip test.tar [To compress a file with an extension .zip]
# unzip -lv test.tar.zip [To read compress data]
# unzip test.tar.zip [To uncompress data]
# bzip2 -v test.tar [To compress a file with an extension .bzip2]
# bzcat -v test.tar.bzip2 [To read compress data]
# bunzip2 -v test.tar.bzip2 [To uncompress data]
# tar -Zcvf test.tar.Z /etc [To create tar file along with compress tool]
# tar -Ztvf test.tar.Z /etc [To read tar file along with compress tool]
# tar -Zxvf test.tar.Z /etc [To extract tar file along with compress tool]
# tar -zcvf test.tar.gz /etc [To read tar file along with gzip tool]
# tar -ztvf test.tar.gz /etc [To read tar file along with gzip tool]
# tar -zxvf test.tar.gz /etc [To extract tar file along with gzip tool]
# tar -jcvf test.tar.bzip2 /etc [To read tar file along with bzip2 tool]
# tar -jtvf test.tar.bzip2 /etc [To read tar file along with bzip2 tool]
# tar -jxvf test.tar.bzip2 /etc [To extract tar file along with bzip2 toolLabels: tar