- 1How to Create a File in Linux
- 2How to Rename a File in Linux
- 3How to Copy a File in Linux
- 4How to Move a File in Linux
- 5How to Delete a File in Linux
- 6How to Create a Directory in Linux
- 7How to Delete a Directory in Linux
- 8How to Copy Directories Recursively in Linux
- 9Delete Directories Recursively in Linux
- 10How to View Hidden Files in Linux
- 11How to Create a Hidden File in Linux
- 12How to Create a Hidden Directory in Linux
- 13How to Find Files in Linux Using find Command
- 14Find Files in Linux Using locate Command
- 15How to View File Contents Using cat in Linux
- 16How to View File Contents Using less in Linux
- 17View File Contents Using the more Command in Linux
- 18Compare Files Using diff Command in Linux
- 19Compare Files in Linux Using cmp Command
- 20Check File Type in Linux with file Command
- 21Create Symbolic Links with ln -s in Linux
- 22How to Archive Files Using tar Command in Linux
- 23Compress Files with gzip in Linux – Beginner Tutorial
- 24How to Compress Files Using bzip2 in Linux
- 25Compress Files in Linux Using zip Command
- 26Extract Compressed Files using tar in Linux
- 27Extract ZIP Files on Linux with unzip
- 28How to Extract .gz Files using gunzip in Linux
How to Extract Compressed Files using tar Command
How to Extract Compressed Files using the tar
Command in Linux
Hey there, and welcome to this hands-on Linux tutorial from ProgramGuru.org! 👋
Today, we're going to walk through one of the most common tasks every Linux user faces — extracting compressed files using the tar
command.
We’ll look at how to handle different archive formats like:
.tar
– just an archive, no compression.tar.gz
or.tgz
– archive + gzip compression.tar.bz2
– archive + bzip2 compression
Let’s get started!
🛠️ 1. Extracting a .tar file
Imagine you’ve downloaded a file called project.tar
. This file is just a collection of files bundled together without compression.
To extract it, run:
tar -xvf project.tar
Let’s break it down:
-x
means extract-v
stands for verbose (shows progress)-f
specifies the file name to work with
Here's what the output might look like:
file1.txt
file2.txt
images/
images/logo.png
🛠️ 2. Extracting a .tar.gz or .tgz file
These files are archived and compressed using gzip. The command is just as simple:
tar -xvzf project.tar.gz
Or if the file is named project.tgz
:
tar -xvzf project.tgz
Here’s the output:
project/
project/main.cpp
project/README.md
And again, here’s what the options mean:
-z
tellstar
to use gzip-xvzf
is the usual combo to extract and see progress
🛠️ 3. Extracting a .tar.bz2 file
If your file uses bzip2 compression, like project.tar.bz2
, you’ll need to use the -j
flag:
tar -xvjf project.tar.bz2
That tells tar to use bzip2 while extracting.
project/
project/index.html
project/style.css
📁 Optional: Extract to a Specific Directory
Want to extract files to a custom folder? Use the -C
option:
tar -xvzf project.tar.gz -C /home/yourname/projects/
✅ Summary
Here’s a quick cheat sheet:
tar -xvf file.tar
– extract .tartar -xvzf file.tar.gz
– extract .tar.gz or .tgztar -xvjf file.tar.bz2
– extract .tar.bz2
And that’s it! You've now mastered the basics of extracting compressed files using tar
in Linux.
Thanks for learning with us at ProgramGuru.org. If this was helpful, be sure to check out our other beginner-friendly Linux guides. 🚀
Next Topic ⮕Extract ZIP Files on Linux with unzip
Comments
Loading comments...