![]() This is because both gzip and bz2 are separate utilities and tar is just utilizing them. The tar command does not have the functionality of adding files if the archive is compressed. The savings here were not very noticeable. 1 savona savona 228K Feb 18 16:08 2Īs you can see bz2 compressed the files even more. Let's take a look at the size difference between tar, gzip and bz2. To compress a tar archive using bz2, add the -j option. It is widely accepted that bzip2 has better compression than gzip but with the drawback of being slower. The bzip2 utility is similar to gzip but it is uses a different set of algorithms. Create a Compressed Archive with bz2 (bzip2) 1 savona savona 309K Feb 18 15:56 Īs you can see using gzip reduced the amount of disk space by over 80%. 1 savona savona 1.9M Feb 18 15:56 definitions.tar Now let's take a look at the differing file sizes between a regular tar archive and a gzipped archive. ![]() 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |