How to unzip tar.gz file in Linux using command line
By Arshath | April 25, 2023
Have you ever come across a file that ends in .tar.gz and wondered what to do with it? Well, you’re not alone! This file type, known as a tarball, is a compressed archive of files and folders. In Linux, it’s simple to extract the contents of a tarball, and in this article, we’ll show you how.
Are you tired of struggling with those confusing archive files? The ones that always seem to keep their contents locked away, just out of reach? Fear not! This guide will show you how to effortlessly extract the full potential of your “.tar.gz” files in Linux, unlocking a world of possibilities and making file management a breeze. So sit back, relax, and let’s get started on this journey to uncompress like a pro!
ALSO READ: What is Linux, Full Form, and Basic Commands
Step-by-step guide to unzip a tar.gz file in Linux:
1. Using Command Line in Terminal
The terminal is a command-line interface that allows you to interact with your Linux operating system. To open it, press “Ctrl + Alt + T” on your keyboard or search for “Terminal” in your applications menu.
2. Navigate to the folder containing the tarball
Use the “cd” command to change to the directory where the tarball is located. For example, if the tarball is in your “Downloads” folder, type “cd ~/Downloads” in the terminal and press “Enter.”
3. Extract the contents of the tarball
To extract the contents of the tarball, type “tar xzvf [filename].tar.gz” in the terminal, replacing “[filename]” with the actual name of your tarball. For example, if the tarball is named “my_files.tar.gz,” type “tar xzvf my_files.tar.gz” in the terminal and press “Enter.”
4. View the contents of the extracted files
Once the extraction process is complete, you’ll find a new folder with the same name as the tarball, but without the .tar.gz extension. Navigate to this folder using the “cd” command, and you’ll be able to view the contents of the extracted files.
That is it! You’ve successfully extracted the contents of a .tar.gz file in Linux. No technical background is required!
ALSO READ: How To Remove Directory in Linux? Delete Folder and Files
We’ll explore the different options available with the “tar” command and how you can use them to make your life easier.
- c (Create)
Use the “c” option to create a new tarball. For example, the command “tar cf [tarball_name].tar [directory_name]” will create a new tarball with the specified name, containing the contents of the directory.
- x (Extract)
Use the “x” option to extract the contents of an existing tarball. For example, the command “tar xf [tarball_name].tar” will extract the contents of the tarball to the current directory.
- z (Compress)
The “z” option allows you to compress the contents of the tarball using gzip compression. For example, the command “tar czf [tarball_name].tar.gz [directory_name]” will create a new tarball with the specified name, containing the contents of the directory, and compress it using gzip.
- v (Verbose)
The “v” option provides verbose output, allowing you to see the progress of the tar command as it runs. For example, the command “tar cvf [tarball_name].tar [directory_name]” will create a new tarball and provide verbose output as it runs.
Conclusion:
In conclusion, unzipping a .tar.gz file in Linux is a straightforward process, and the terminal makes it easy for anyone to extract the contents of a tarball, regardless of their technical background. So next time you come across a tarball, you’ll know exactly what to do.