In addition to compression, the tar (tape archive) utility is very often used to group files into an archive known as a tarball and then compress the whole archive together. Creating a single file bundle by putting multiple files together is known as archiving.
The various options used with the tar command are given, with their descriptions, in the following table:
tar command option |
Description |
c |
Creates an new archive |
v |
Verbosity, used to see which files are being added and extracted |
f |
Filename of the archive to operate on |
x |
Extracts an archive |
t |
Lists the contents of an archive |
z |
Uses .gzip compression (.tar.gz) |
j |
Uses .bzip2 compression (.tar.bz2), better than .gzip |
J |
Uses .xz compression (.tar.xz), better than .bzip2 |
The tarball archives can be compressed using .gzip, .bzip2, or .xz compression with tar command itself.
The following table lists the usage of the tar command with compression utility:
Command |
Description |
Tar cvf abc.tar file1 file2 file3 |
Archives the file1, file2, and file2 files and puts them into one single file, abc.tar |
Tar xvf abc.tar |
Extracts all the files in the abc.tar archive in the current directory |
Tar tvf abc.tar |
Lists all the files available inside the abc.tar archive |
Tar cvzf abc.tar.gz * |
Creates an abc.tar.gz archive of all the files in the current directory and compresses it with .gzip |
Tar cvjf abc.tar.bz2 * |
Creates an abc.tar.bz2 archive of all the files in the current directory and compresses it with .bzip2 |
Tar cvJf abc.tar.xz * |
Creates an abc.tar.xz archive of all the files in the current directory and compresses it with .xz |
Tar xvf abc.tar.gz abc.tar.bz2 abc.tar.xz |
Extracts all the files in abc.tar.gz, abc.tar.bz2, and abc.tar.xz in the current directory |