
Always make sure that the directory into which you want to extract tar file exists. In the first example, I will extract the files in articles.tar to a directory /tmp/my_article. Example 1: Extracting tar Files to a Specific Directory tar -xvzf ukulele_ us now look at some examples below. The files and directories that would have been extracted to that directory are extracted in the target directory.

If we specify -strip-components=1 with our example tar file, the Ukulele Songs top-most directory within the tar file is not created on the hard drive. Files from the ignored directories are still extracted, but the directory structure is not replicated on your hard drive. The number represents how many levels of directories to ignore. The -strip-components option requires a numerical parameter. If you don’t want the directory structure in the tar file to be recreated on your hard drive, use the -strip-components option. tar -xvz -wildcards -f ukulele_ "Ukulele Songs/Possibles/B*"Įxtracting Files Without Extracting Directories Using wildcards requires the use of the -wildcards option. You can extract a selection of files by using wildcards, where * represents any string of characters and ? represents any single character. tar -xvzf ukulele_ "Ukulele Songs/023 - My Babe.odt" To extract a single file, provide the path and the name of the file. If we want to extract the files to a location other than the current directory, we can specify a target directory using the -C (specified directory) option.

#UNTAR .TAR DOWNLOAD#
If we list the files in the Download directory we will see that another directory called Guitar Songs has been created.


-v: Verbose, list the files as they are being extracted.-x: Extract, retrieve the files from the tar file.Let’s extract the ukulele songs: tar -xvzf ukulele_Īs the files are extracted, they are listed in the terminal window. These files are in the Downloads directory. One file is called ukulele_, the other is called guitar_2. Let’s say you’ve downloaded two files of sheet music. You just need to use the appropriate tar command line options.
#UNTAR .TAR ARCHIVE#
bz2 extension suffix indicates that the archive has been compressed, using either the gzip or bzip2 compression algorithm. The tar command will work happily with both types of file, so it doesn’t matter which compression method was used-and it should be available everywhere you have a Bash shell.
