
- #Linux untar to a specific directory how to#
- #Linux untar to a specific directory archive#
#Linux untar to a specific directory archive#
You can add additional files to an existing tar archive as shown below. Adding a file or directory to an existing archive using option -r
–wildcards *.pl – files with pl extensionĨ. $ tar xvf archive_file.tar -wildcards '*.pl' For example, following tar command extracts all the files with pl extension. You can specify a regex, to extract files matching a specified pattern. Extract group of files from tar, tar.gz, tar.bz2 archives using regular expression Use the relevant option z or j according to the compression method gzip or bzip2 respectively as shown below. $ tar xvf archive_file.tar /path/to/dir1/ /path/to/dir2/ To extract multiple directories from a tar archive, specify those individual directory names at the end of the tar xvf command as shown below. The following extracts only a specific directory from a large tar file. To extract a single directory (along with it’s subdirectory and files) from a tar archive, specify the directory name at the end of the tar xvf command as shown below. Extract a single directory from tar, tar.gz, tar.bz2 file The following command extracts only a specific file from a large tar file. To extract a specific file from a tar archive, specify the file name at the end of the tar xvf command as shown below. Extract a single file from tar, tar.gz, tar.bz2 file But, you can also use less command directly to view the tar archive output, as explained in one of our previous article Open & View 10 Different File Types with Linux Less Command - The Ultimate Power of Less. When the number of files in an archive is more, you may pipe the output of tar to less. Listing out the tar file content with less command You can view the *.tar.bz2 file content before extracting as shown below. $ tar tvfz archive_ View the *.tar.bz2 file content without extracting using option tvjf You can view the *.tar.gz file content before extracting as shown below. $ tar tvf archive_name.tar View the *.tar.gz file content without extracting using option tvzf You can view the *.tar file content before extracting as shown below. Listing an archive using tar command View the tar archive file content without extracting using option tvf Note: In all the above commands v is optional, which lists the file being processed. Use the option j for uncompressing a bzip2 tar archive. $ tar xvfz archive_ Extracting a bzipped tar archive ( *.tar.bz2 ) using option xvjf Use the option z for uncompressing a gzip tar archive.
Extracting (untar) an archive using tar command Extract a *.tar file using option xvfĮxtract a tar file using option x as shown below: $ tar xvf archive_name.tarĮxtract a gzipped tar archive ( *.tar.gz ) using option xvzf Gzip vs bzip2: bzip2 takes more time to compress and decompress than gzip. i.e cvf for archive creation, cvfz for compressed gzip archive creation, cvfj for compressed bzip2 archive creation etc., For this method to work properly, don’t give – in front of the options.Ĭreating a bzipped tar archive using option cvjfĬreate a bzip2 tar archive as shown below: $ tar cvfj archive_2 dirname/ Note: I like to keep the ‘cvf’ (or tvf, or xvf) option unchanged for all archive creation (or view, or extract) and add additional option at the end, which is easier to remember. To use a gzip compression on the tar archive, use the z option as shown below. The above tar cvf option, does not provide any compression. v – verbosely list files which are processed.Ĭreating a tar gzipped archive using option cvzf.This is the basic command to create a tar archive.
Creating an archive using tar command Creating an uncompressed tar archive using option cvf
#Linux untar to a specific directory how to#
In this article, let us review various tar examples including how to create tar archives (with gzip and bzip compression), extract a single file or directory, view tar archive contents, validate the integrity of tar archives, finding out the difference between tar archive and file system, estimate the size of the tar archives before creating it etc.,ġ. Understanding various tar command options will help you master the archive file manipulation. On Unix platform, tar command is the primary archiving utility.