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. In this tutorial we will learn how to use Linux and UNIX TAR command.
Linux and Unix TAR Command
Create tar Archive File
Example command create a tar archive file wpcademy.tar for a directory /home/wpcademy in current working directory.
#tar -cvf wpcademy.tar /home/wpcademy/ /home/wpcademy/ /home/wpcademy/install.sh /home/wpcademy/openvpn-2.0.9-1.tar.gz
Create tar.gz Archive File
Example command create a compressed gzip archive file wpcademy.tar for a directory /home/wpcademy in current working directory.
#tar cvzf Mythemes.tar.gz /home/wpcademy /home/wpcademy/ /home/wpcademy/kardun /home/wpcademy/eleganthemes /home/wpcademy/adsready
Untar a tar File or gzip-bz2 tar File
#tar xvzf wpcademy.gz - for uncompress a gzip tar file (.tgz or .tar.gz) #tar xvjf wpcademy.tar.bz2 - for uncompress a bzip2 tar file (.tbz or .tar.bz2) #tar xvf wpcademy.tar - for uncompressed tar file (.tar)
Tar Command Options
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.