How To Extract .tar.gz Files using Linux Command Line
A
.tar.gz
.tar
.gz
.tar.gz
Basic Syntax for Extracting.tar.gz
Files
.tar.gz
To extract a
.tar.gz
tar
tar -xzvf archive-name.tar.gz
Here’s what each option means:
- -x: Extract the files from the archive.
- -z: Useto decompress the
gzip
file..gz
- -v: Verbose output, which lists the files being extracted.
- -f: Specifies the archive file name.
Step-by-Step Instructions
- Open Terminal: Press+
Ctrl
+Alt
on your keyboard to open the terminal on most Linux systems.T
- Navigate to the Directory: Change to the directory where yourfile is located using the
.tar.gz
command:cd
cd /path/to/directory
- Extract theFile: Run the following command to extract the contents:
.tar.gz
tar -xzvf archive-name.tar.gz
Replace
with the name of your file.archive-name.tar.gz
Example:
If you have a file called
sample-archive.tar.gz
Downloads
cd ~/Downloads
tar -xzvf sample-archive.tar.gz
Extracting to a Specific Directory
To extract the contents of a
.tar.gz
-C
tar -xzvf archive-name.tar.gz -C /path/to/destination
This command will extract the contents of
archive-name.tar.gz
Example:
If you want to extract
sample-archive.tar.gz
my-files
mkdir ~/my-files
tar -xzvf sample-archive.tar.gz -C ~/my-files
Extracting .tar.gz Files Without Verbose Output
If you prefer not to see the list of files being extracted, you can omit the
-v
tar -xzf archive-name.tar.gz
This command will still extract the files but without displaying them in the terminal.
Viewing Contents Without Extracting
To list the contents of a
.tar.gz
-t
tar -tzvf archive-name.tar.gz
This command shows you the files and directories contained in the archive without extracting them.
Extracting .tar Files (Without .gz Compression)
If you have a
.tar
.gz
tar -xvf archive-name.tar
The
-z
gzip
Conclusion
Extracting
.tar.gz
tar
-xzvf
-C
.tar.gz