Sometimes instead of extracting the whole archive, you might need to extract only a few files from it. The command is the same as when extracting tar archive: tar -xf tar -xf 2 Extracting Specific Files from a Tar Archive # , you do not have to specify a decompression option. When extracting compressed archives such as tar.gz Use the -directory ( -C) to extract archive files in a specific directory:įor example, to extract the archive contents to the /opt/files directory, you can use: tar -xf archive.tar -C /opt/files Extracting Tar Gz and Tar Bz2 Archives # tar -xvf archive.tar Extracting Tar Archive in a Different Directory #īy default, tar will extract the archive contents in the current working directory It is also common to add the -v option to print the names of the files being extracted. To extract a tar archive, use the -extract ( -x) option followed by the archive name: tar -xf archive.tar Knowing how to extract these files from the command line is important. Most of the archived files in Linux are archived and compressed using a tar or tar.gz format. Use the -verbose ( -v) option: tar -tvf archive.tar -rw-r-r- linuxize/users 0 01:19 file1 -rw-r-r- linuxize/users 0 01:19 file2 -rw-r-r- linuxize/users 0 01:19 file3 Extracting Tar Archive # To get more information such as the file owner The command below, will list the content of the archive.tar file: tar -tf archive.tar file1 file2 file3 When used with the -list ( -t) option, the tar command lists the content of a tar archive without extracting it. The following command creates a tar.bz2 archive from the given files: tar -cjf 2 file1 file2 Listing Tar Archives # To compress the archive with the bzip2 algorithm, invoke tar with the -j option. When using bzip2, the archive name should end with either tar.bz2 or tbz. For example, to create a tar.gzĪrchive from given files, you would run the following command: tar -czf file1 file2 Creating Tar Bz2 Archive #Īnother popular algorithm for compressing tar files is bzip2. The -z option tells tar to compress the archive using the gzip algorithm as it is created. When compressing tar archives with gzip, the archive name should end with either tar.gz or tgz. Gzip is the most popular algorithm for compressing tar files. Use the -v option if you want to see the files that are being processed. The following example will create an archive named user_backup.tar of the /home/user directory: tar -cf backup.tar /home/user By default, directories are archived recursively unless -no-recursion option is specified. You can create archives from the contents of one or more directories or files. Here is the equivalent command using the long-form options: tar -create -file=archive.tar file1 file2 file3 To create a tar archive, use the -c option followed by -f and the name of the archive.įor example, to create an archive named archive.tar from the files named file1, file2, file3, you would run the following command: tar -cf archive.tar file1 file2 file3 For example, if an archive has been compressed with gzip When creating compressed tar archives, it is an accepted convention to append the compressor suffix to the archive file name. Tar supports a vast range of compression programs such as gzip, bzip2, lzip, lzma, lzop, xz and compress. The short-form options are prefixed with a single dash ( -), which can be omitted. The long-form options are prefixed with a double dash ( -). The long forms are more readable, while the short forms are faster to type. When executing tar commands, you can use the long or the short form of the tar operations and options. If not provided, the entire archive is extracted. FILE_NAME(s) - A space-separated list of filenames to be extracted from the archive.ARCHIVE_NAME - The name of the archive.-file=archive=name ( -f archive-name) - Specifies the archive file name.-verbose ( -v) - Show the files being processed by the tar command.The most frequently used operations are: -list ( -t) - Display a list of the files included in the archive.-extract ( -x) - Extract the entire archive or one or more files from an archive.-create ( -c) - Create a new tar archive.OPERATION - Only one operation argument is allowed and required.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |