It is often convenient to use tar with a wildcard (i.e., a character which can represent some specific class of characters or sequence of characters). For example, the contents of two directories named dir1 and dir2 could be archived into a file named dir.tar with the following: The result is recursive that is, it includes all objects (e.g., directories and files) within each level of directories. Tar can also be used to make archives from the contents of one or more directories. In such case, the above example would become The -v (i.e., verbose) option is commonly used together with the -c and -f options in order to display a list of the files that are included in the archive. It is necessary, however, that the -f option be the final option in a sequence of contiguous, single-letter options otherwise, the system will become confused as to the desired name for the new file and will use the next option in the sequence as the name. tar extension however, the use of this extension can be is very convenient because it allows the type of file to be visually identified. It it not absolutely necessary that the new file have the. Thus, for example, the following would create an archive file called file.tar from the three files named file1, file2 and file3 that are located in the current directory (i.e., the directory in which the user is currently working): The former instructs tar to create an archive and the latter indicates that the next argument (i.e., piece of input data in a command) will be the name of the new archive file. Tar files are created by using both the -c and -f options. Unlike many commands, tar requires the use of at least one option, and usually two or more are necessary. Tar has numerous options, many of which are not frequently used. However, it is very easy to compress archives created with tar by using specialized compression utilities. Unlike some other archiving programs, and consistent with the Unix philosophy that each individual program should be designed to do only one thing but do it well, tar does not perform compression. Archives that have been created with tar are commonly referred to as tarballs. Moreover, they are very easy to work with, often much more so than dealing with large numbers of individual files.Īlthough tar was originally designed for backups on magnetic tape, it can now be used to create archive files anywhere on a filesystem. Archives are convenient for storing files as well as for for transmitting data and distributing programs. The tar (i.e., tape archive) command is used to convert a group of files into an archive.Īn archive is a single file that contains any number of individual files plus information to allow them to be restored to their original form by one or more extraction programs. Join the nixCraft community via RSS Feed, Email Newsletter or follow on Twitter.How to use the tar command, by The Linux Information Project (LINFO) LINFO He wrote more than 7k+ posts and helped numerous readers to master IT topics. Vivek Gite is the founder of nixCraft, the oldest running blog about Linux and open source. Hence, I suggest that you read the tar command help page here. This page explained the basic syntax of tar, and I hope you learned how to compress files with tar command running on Linux, FreeBSD, OpenBSD, macOS, and Unix-like operating systems. $ tar -tvjf 2 To extract the contents of a tar file, enter: $ tar -cv jf 2 /home/vivek/Documents/ To list the contents of a tar file, enter: To compress the tar file with bzip2 pass the -j option, run: To compress the tar file with gzip pass the -z option, run: $ tar -cvf backup.tar /etc/nf /etc/hosts /home/vivek/project1 Compressing Files at the Shell Promptįor compressing files you need to use the compression utilities: The following adds file named /etc/nf, /etc/hosts, and /home/vivek/project1 directory: home/vivek/Documents/Scanned Document.pdf home/vivek/Documents/info-needed/Shipment invoice.pdf home/vivek/Documents/info-needed/t2016-17.pdf home/vivek/Documents/info-needed/chair-bill.pdf home/vivek/Documents/info-needed/server.pdf Tar: Removing leading `/ ' from member names
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |