How To Extract - Unzip Tar - GZ Files From Linux Command Line
How To Extract - Unzip Tar - GZ Files From Linux Command Line
Home » DevOps and Development » How to Extract or Unzip tar.gz Files from Linux
Command Line
Introduction
A tar.gz file contains several compressed files to save storage space, as well as
bandwidth during the downloading process. The .tar file acts as a portable container for
other files and is sometimes called a tarball. The .gz part of the extension, stands for
gzip, a commonly-used compression utility.
In this guide you will learn how to extract or unzip files from tar.gz files using command-
line in Linux.
https://phoenixnap.com/kb/extract-tar-gz-files-linux-command-line 1/7
9/18/21, 4:42 PM How To Extract / Unzip tar.gz Files From Linux Command Line
Prerequisites
Below, we have used the file named test.txt. Use the name of the file you want to
compress instead.
to compress a single file with gzip enter the command in your terminal window:
gzip test.txt
After zipping the file, enter the command ls to confirm that the file has been compressed.
The output confirms that the file now has a .gz extension.
https://phoenixnap.com/kb/extract-tar-gz-files-linux-command-line 2/7
9/18/21, 4:42 PM How To Extract / Unzip tar.gz Files From Linux Command Line
gunzip test.txt
gzip *.txt
The * sign is a wildcard, which means “any number of any characters.” This command
would work on any (and all) filenames with the extension .txt.
This technique can be used on other file types including gzip.txt, .jpg, and .doc.
When you run gzip on multiple files at once, the system generates a compressed copy of
each file. This can clutter up a directory quickly! Fortunately, there’s another tool to
manage multiple files at once.
You can unzip these files the same way you would unzip a regular zipped file:
https://phoenixnap.com/kb/extract-tar-gz-files-linux-command-line 3/7
9/18/21, 4:42 PM How To Extract / Unzip tar.gz Files From Linux Command Line
To list the contents of a .tar file before you extract it, enter:
To instruct tar to put the extracted unzipped files into a specific directory, enter:
https://phoenixnap.com/kb/extract-tar-gz-files-linux-command-line 4/7
9/18/21, 4:42 PM How To Extract / Unzip tar.gz Files From Linux Command Line
Similar to the tar command, it condenses all the content located in the
/home/user/Documents directory into a single file, called documents.tar.gz. The addition
of the –z option is what signals tar to compress the files.
This copies the contents of your Documents folder into a single file, called documents.tar.
The options -cvf work as follows:
Dejan Tucakov
tar –xvf documents.tar
Dejan is the Head of Content at phoenixNAP with over 7 years of experience in Web
This command extracts and lists all files from the documents.tar file. The -x option tells
publishing and technical writing. Prior to joining PNAP, he was Chief Editor of several
tar to extract the files.
websites striving to advocate for emerging technologies. He is dedicated to simplifying
complex notions and providing meaningful insight into data center and cloud technology.
https://phoenixnap.com/kb/extract-tar-gz-files-linux-command-line 5/7
9/18/21, 4:42 PM How To Extract / Unzip tar.gz Files From Linux Command Line
You can also use xargs with tar to create a tar.gz archive and populate it with files from
Next you should read
the find command.
SysAdmin,
Web
Servers Note: Some graphical interfaces include a tool for managing tar.gz files
without the command-line. Simply right-click the item you want to
Linux Commands
compress, mouseover compress, and choose tar.gz. You can also right-
Cheat Sheet: With
click a tar.gz file, mouseover extract, and select an option to unpack the
Examples archive.
February 21, 2020
Conclusion
A list of all the
important Linux
commands in one
This tutorial explains how to use the tar tool, the gzip tool, and how to utilize them
place. Find the
together to work with tar.gz files. You are now ready to extract or unzip any tar.gz file.
command you need,
whenever you need it
Was this article helpful?
or... Yes No
READ MORE
SysAdmin
How to Unzip a
ZIP File in Ubuntu
/ Linux
December 2, 2019
Security,
SysAdmin
19 Common SSH
Commands in
Linux With
Examples
https://phoenixnap.com/kb/extract-tar-gz-files-linux-command-line 6/7
9/18/21, 4:42 PM How To Extract / Unzip tar.gz Files From Linux Command Line
Secure Shell is an
important protocol for
anyone managing and
controlling remote
machines. This guide
covers...
READ MORE
Security,
Web Servers
How to Set up &
Configure
ModSecurity on
Apache
March 11, 2019
ModSecurity is an
Open-source firewall
application for Apache.
Learn how to Setup &
Configure ModSecurity
on...
READ MORE
Live Chat
Get a Quote
Support | 1-855-330-1509
Sales | 1-877-588-5918
Privacy Policy GDPR Sitemap © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.
https://phoenixnap.com/kb/extract-tar-gz-files-linux-command-line 7/7