x32x01
ADMINISTRATOR
The Linux tar command stands for tap archive, is not a compressed file and commonly called as a collection (which contains the contents of many files) of a single file.
Tar is the most commonly used command in Linux for creating a archive file. It saves multiple files, folders & other file formats (zip, gzip, bzip2 & tar) into a single archive file. Many of us very frequently uses three operations create, list & extract & two options file & verbose with tar to dealing the backups and restore.
Additionally we can use gzip & bzip2 commands for further compressing the tar archive. Mainly tar command used to performing backup (full and incremental) from the server by server administrator, other famous backup applications are using tar command for backup.
All the files and folders can be restore from the archive file whenever you want, every server administrator need to know the tar command and it’s usage for better backup solution.
By default tar command included into most of the distribution, so we can easily install from distribution official repository.
Example 1 – To create a new archive of folder named Yeahhub which contains 3 files named document.docx, file.txt and song.mp3, the command is:
Code:
tar cf file1.tar Yeahhub
Where c refers to the creation of new archive and f is the specified archive file.

Code:
tar cf file2.tar document.docx file.txt song.mp3

Code:
tar xf file1.tar
Where x refers for extraction.

Code:
tar xf file1.tar -C Downloads

Code:
tar -xf file.tar –wildcards “*.docx”
The above command will only extract .docx extension files from the tar file.

To create a .tar.gz archive, the command is:
Code:
tar czf compressedfile.tar.gz Yeahhub/
Where z flag is used for gzip compression.

Code:
tar czf compressed.tgz Yeahhub/

Code:
tar czvf newfile.tar.gz Yeahhub/

Code:
tar czf compressedfile.tar.gz document.docx file.txt song.mp3

Code:
tar xzf compressedfile.tar.gz

Code:
tar xzf compressedfile.tar.gz -C /root/Downloads/

Code:
tar cjf newfile.tar.bz2 Yeahhub/

Code:
tar cjf file.tbz Yeahhub/

Code:
tar cjf newfile.tar.bz2 document.docx file.txt song.mp3

Code:
tar xjf newfile.tar.bz2

Code:
tar xjf newfile.tar.bz2 -C /root/Downloads/

Code:
tar czvf newfile.tar.gz Downloads/ Music/ Yeahhub/file.txt

Code:
tar tf file.tgz

Code:
tar tvf file.tgz

Code:
tar rf newfile.tar Hub/newfile.txt
