For those of you who didn’t know, 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. The main purpose of this article is to provide various tar command examples that might be helpful you to understand and become expert in tar archive manipulation.
Linux and Unix TAR Command
Create tar Archive File
Example command create a tar archive file idroot.tar for a directory /home/idroot in current working directory.
1 2 3 4 5 | #tar -cvf idroot.tar /home/idroot/ /home/idroot/ /home/idroot/install.sh /home/idroot/openvpn-2.0.9-1.tar.gz |
Create tar.gz Archive File
Example command create a compressed gzip archive file idroot.tar for a directory /home/idroot in current working directory.
1 2 3 4 5 6 | #tar cvzf Mythemes.tar.gz /home/idroot /home/idroot/ /home/idroot/kardun /home/idroot/eleganthemes /home/idroot/adsready |
Untar a tar File or gzip-bz2 tar File
1 2 3 | #tar xvzf idroot.gz - for uncompress a gzip tar file (.tgz or .tar.gz) #tar xvjf idroot.tar.bz2 - for uncompress a bzip2 tar file (.tbz or .tar.bz2) #tar xvf idroot.tar - for uncompressed tar file (.tar) |
1 2 3 4 5 6 7 8 9 | c – create a archive file. x – extract a archive file. v – show the progress of archive file. f – filename of archive file. t – viewing content of archive file. j – filter archive through bzip2. z – filter archive through gzip. r – append or update files or directories to existing archive file. W – Verify a archive file. |