The Linux “tar” stands for tape archive, which is used by large number of Linux/Unix system administrators to deal with tape drives backup.
The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux.
The tar is most widely used command to create compressed archive files and that can be moved easily from one disk to anther disk or machine to machine.
1. To create a “TAR” backup of all files & folders under /home/sam/**
# cd /home/sam/
# tar -cvf sam.tar . (dot at the end is represent all files/folders in current directory )
or tar -cvf sam.tar /home/same
- c – Creates a new .tar archive file.
- v – Verbosely show the .tar file progress.
- f – File name type of the archive file.
2. To extract the “TAR” file
# tar -xvf sam.tar
3. To list the content on TAR file
# tar -tvf sam.tar
4. To create /extract TAR file with compression (gzip or bzip2)
gzip vs bzip2:
bzip2 takes more time to compress and decompress than gzip. bzip2 archival size is less than gzip.
# tar -cvfj archive_name.tar.bz2 /home/sam/
# tar -cvzf archive_name.tar.gz /home/sam/
tar cvzf archive_name.tar.gz dirname/
or untar the gzip file
# tar -xvfz archive_name.tar.gz5. Compress & Un-compress files with out TAR:
To compress a file, type:
# gzip file
# bzip2 file
To uncompress a file, type:
# gunzip file.gz
# bunzip2 file.bz2