

To compress a tar archive using gzip, add the -z option.

The gzip utility is a fast and efficient means of compression. Here we use gzip to compress the tar archive and see big space savings. Create a Compressed Archive with gzip (GNU zip)Ĭompressing a tar archive requires a separate utility. There are several methods for compressing a tar archive. If you are creating a tar archive of a lot of small files, you may see a reduction of space depending on your file systems block size (a whole different article). Compressing tar Archivesīy default tar does not compress any data, it simply collects all the files and produces a single file. $ tar rvf definitions.tar /usr/share/doc/dictd Now let's add the the /usr/share/doc/dictd directory to definitions.tar. $ tar rvf definitions.tar /usr/share/dict/linux.words Let's add /usr/share/dict/linux.words to our tar archive using the -r option. You can add (or append) a file or directory to a tar archive after it has been created. To clarify, if you create an archive by providing a path to files, the file directory structure will be recreated in the location the extraction is taking place. The way you create a tar archive will dictate the way it extracts. $ tar cvf definitions.tar /home/savona/words/ To see the files being added to the archive we just need to add the -v (verbose) option. $ tar cfP definitions.tar /home/savona/words/Īlthough this did exactly what we wanted it to, it would be nice to see the names of the files being added to the archive. If you really want to create an archive with absolute paths, use the -P option. Which most of the time, is not what you want. If tar did not remove the leading '/' from the filenames it would extract to absolute paths. The tar output is warning us that it is removing the forward slash from the filenames. Tar: Removing leading `/' from member names $ tar cf definitions.tar /home/savona/words/ Here we will create a tar archive file called definitions.tar from all the files in the /home/savona/words/ folder. The most basic way to create a tar archive is using the -cf options (create, file). This is because it specifies the destination (archive) before the source (files to be archived). The basic syntax of tar in slightly counter intuitive to most Linux beginners. Extracting Multiple Files from an Archive.Extracting a Single File from an Archive.

Extract Archive to a Different Directory.Create a Compressed Archive with bz2 (bzip2).Create a Compressed Archive with gzip (GNU zip).The *.tar.bz2 can be untarred like below. The bz2 is another popular compression format where tar can be compressed with it. In the following example, we extract the tar.gz file. The tar files can be compressed with the gzip as gz format.

#Untar command not found linux how to#
In the tutorial, we examine how to untar files with different compressions algorithms like gz, bz2 etc. The most important function of the tar format is the ability to store multiple files and directories as a single file where it can be easily compressed. The tar format is used with different compression algorithms like gz, bz2, etc. The *.tar is a popular archive format used to compress files in Linux and Unix operating systems.
