
Join the nixCraft community via RSS Feed, Email Newsletter or follow on Twitter. 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. See tar command man page for further information by typing the following man command: We use the tar command on Linux to extract files from tarball archives. tar -xvzf ukulele_ to extract files to dir called /tmp/out? Try the following syntax to change to /tmp/out before performing any operations using tar: 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.
#Unzip tar file linux download
If we list the files in the Download directory we will see that another directory called Guitar Songs has been created. -f: File, name of the tar file we want tar to work with.-j: Bzip2, use bzip2 to decompress the tar file.

-x: Extract, retrieve the files from of the tar file.To be clear, the command line options we used with tar for the. Once again, the files are listed to the terminal as they are extracted. Instead of using the -z (gzip) option, we will use the -j (bzip2) option. bz2 extension suffix tells us it has been compressed using the bzip2 command. To do this we’ll use almost exactly the same command as before but with one important difference. Where did this directory come from? It was contained in the tar file, and was extracted along with the files.

The extracted files are in that directory.
tar -tvf < tararchive > Let’s have a quick breakdown of the flags we used. tar -cvJf < sourcefiledirectory > Extracting tar files List tar content The following tar command will list all the files and directories included in the tar archive.#Unzip tar file linux archive
List the files in the directory with ls and you’ll see that a directory has been created called Ukulele Songs. To create a tar archive using XZ compression, use the following command. This option must be followed by the name of the tar file. -f: File, the name of the tar file we want tar to work with.-z: Gzip, use gzip to decompress the tar file.-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. 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.
