March 22, 2024

Unzip (decompress) and extract files from a .tar.gz file


$ tar -xvzf file.tar.gz

First a reminder:

why do we end up with a .tar.gz file?

tar collects multiple files to create one single file. Then, we use gzip to compress that single .tar file into a .gz file, thus the compound .tar.gz extension.

So to reverse the process, we first need to decompress file.tar.gz using gzip, and then extract the files from the remaining file.tar.

What do the options we pass mean?

  • z tells tar to decompress the file using gzip
  • x extracts all files from the .tar file.
  • f tells tar the path and name of the file to decompress and extract; this must be the last flag of the command, and the .tar.gz file must come right after.
  • v makes tar list all the files being extracted in the terminal as the command runs

To extract into a specific folder, pass the -C option to the command followed by the name of the folder where you want tar to extract the files:

$ tar -xvzf file.tar.gz -C folder

personal computing command-line interface (cli) gnu linux trisquel shell literacy office applications wiki tar

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2024 by yctct is licensed under CC BY-ND 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88