![]() ![]() The basic syntax of tar in slightly counter intuitive to most Linux beginners. This is because it specifies the destination (archive) before the source (files to be archived). The most basic way to create a tar archive is using the -cf options (create, file). 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 tar output is warning us that it is removing the forward slash from the filenames. If tar did not remove the leading '/' from the filenames it would extract to absolute paths. ![]() Which most of the time, is not what you want. If you really want to create an archive with absolute paths, use the -P 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. $ 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. The way you create a tar archive will dictate the way it extracts. 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. You can add (or append) a file or directory to a tar archive after it has been created. $ 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. $ tar rvf definitions.tar /usr/share/doc/dictd Now let's add the the /usr/share/doc/dictd directory to definitions.tar. Compressing tar Archivesīy default tar does not compress any data, it simply collects all the files and produces a single file. 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). There are several methods for compressing a tar archive. ![]() Create a Compressed Archive with gzip (GNU zip)Ĭompressing a tar archive requires a separate utility. Here we use gzip to compress the tar archive and see big space savings. The gzip utility is a fast and efficient means of compression. To compress a tar archive using gzip, add the -z option.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |