- 1 1. What Is a tar.gz File? The Basics
- 2 2. How to Extract tar.gz Files on Ubuntu (Terminal Commands)
- 3 3. Common Extraction Patterns (Practical Commands You’ll Use Often)
- 4 4. Extracting via GUI (Ubuntu’s Default File Manager)
- 5 5. Advanced: Extract Only Specific Files (Grab What You Need)
- 6 6. Common Errors and Fixes (Troubleshooting Checklist)
- 6.1 6.1 tar: ...: Cannot open: No such file or directory (File not found)
- 6.2 6.2 tar: This does not look like a tar archive (Not a tar archive)
- 6.3 6.3 gzip: stdin: not in gzip format (Not gzip-compressed)
- 6.4 6.4 Permission denied (No permission to write)
- 6.5 6.5 Extraction worked, but “I don’t know where the files went”
- 6.6 6.6 Filenames become garbled after extraction (mojibake)
- 7 7. How to Create a tar.gz File (Bonus: Useful for Packaging Too)
- 8 8. Summary: The Fastest Way to Extract tar.gz on Ubuntu
- 9 FAQ (Frequently Asked Questions)
- 9.1 Q1. What is the easiest way to extract a tar.gz file on Ubuntu?
- 9.2 Q2. Can I choose the destination folder when extracting?
- 9.3 Q3. Can I preview the contents without extracting?
- 9.4 Q4. Can I extract tar.gz files using the GUI (right-click)?
- 9.5 Q5. I get not a tar archive and it won’t extract
- 9.6 Q6. I also want to know how to create a tar.gz file
1. What Is a tar.gz File? The Basics
If you’re trying to extract a tar.gz file on Ubuntu, it helps to first understand what a tar.gz actually is. Once you know that, the commands will make a lot more sense. This section explains only what beginners need, in a simple way.
1.1 tar.gz combines “archiving” and “compression”
tar.gz is, in short, a file that bundles multiple files/folders into one and then compresses that bundle.
- tar: an archive format used to “bundle” multiple files into one (an archive)
- gz: a file extension showing it was “compressed” using gzip
So, a tar.gz file is essentially two steps combined:
- Bundle files/folders together (tar)
- Compress the bundle (gzip)
That’s why on Ubuntu, “extracting” a tar.gz is more accurately described as “decompressing first, then unpacking the archive.”
1.2 Why tar.gz is so common on Ubuntu
In Linux environments (including Ubuntu), tar.gz files are extremely common. The reason is simple: they’re a great fit for these use cases.
- Software distribution: easy to ship a full set of source code and/or binaries
- Backups: you can pack an entire folder into one file
- Storing logs and config files: easier to organize lots of small files
In particular, tools you download from the web and packages distributed on GitHub are often provided as tar.gz archives.
1.3 Differences from similar extensions (.tgz / .tar / .gz)
There are a few similar-looking extensions that commonly confuse beginners, so let’s clarify them.
• .tgz is a shorter version of .tar.gz
.tgz is effectively the same as .tar.gz.
It’s an older shorthand that’s still used sometimes.
• .tar is “archived only” (not compressed)
.tar is only an archive (bundled), with no compression.
It tends to stay large in file size.
• .gz often means “a single file compressed”
.gz is basically a compression format.
In many cases, it’s just a single file that was gzip-compressed (for example, log.txt.gz), and it may not include tar at all.
For this article, just remember: tar.gz means “archive (tar) + compression (gzip)” together.
1.4 What to know before extracting (to avoid common mistakes)
Beginners often get stuck on two points: “Where will the files be extracted?” and “Is the content safe?” Keep these ideas in mind to stay safe and organized.
- By default, extraction happens in your “current folder”
- It’s safer to preview the contents before extracting
- If you specify an extraction folder, you can unpack neatly into Desktop or any folder you want
In the next chapter, we’ll walk through the actual commands and show exactly how to do this step by step.
2. How to Extract tar.gz Files on Ubuntu (Terminal Commands)
There are two main ways to extract a tar.gz file on Ubuntu:
- Extracting via Terminal (commands) ← most common and reliable
- Extracting via GUI (right-click) ← easy, but less flexible
This article first focuses on command-based extraction, because it’s the easiest to reproduce and troubleshoot—even for beginners.
2.1 The most basic extraction command (memorize this first)
This is the standard command to extract a tar.gz file on Ubuntu:
tar -xzvf filename.tar.gzFor example, if the file you downloaded is sample.tar.gz, use:
tar -xzvf sample.tar.gzThis will extract the contents into the folder you’re currently in (the current directory).
2.2 Breaking down tar -xzvf for beginners
It may look intimidating at first, but once you know what each part means, it’s straightforward.
tar: the command used to work with archives-x: extract-z: handle gzip compression (.gz)-v: show file names while extracting (verbose)-f: specify the file name (file)
In other words:
“Extract a gzip-compressed tar archive from the specified file, while printing details.”
As a beginner, it’s perfectly fine to simply memorize tar -xzvf as a set.
2.3 Before extracting: move to the folder where the file is
If you get “file not found,” the most common reason is that you’re running the command in the wrong folder.
For example, files downloaded via a browser are usually saved in the Downloads folder.
In Terminal, you can move there like this:
cd ~/DownloadsThen check that the file is actually there:
lsOnce you see sample.tar.gz, run the extraction command:
tar -xzvf sample.tar.gz2.4 If the filename contains spaces
If a filename contains spaces, the command will break in the middle and cause an error.
Example:
my app.tar.gz(contains a space)
In that case, the easiest fix is to wrap the filename in double quotes:
tar -xzvf "my app.tar.gz"Alternatively, you can escape the space using \:
tar -xzvf my\ app.tar.gzFor beginners, the quote method is usually easier to read.
2.5 What happens after extraction? Visualizing the folder structure
In many cases, extracting a tar.gz results in something like this:
- Extract
sample.tar.gz
→ asample/folder is created, and everything is unpacked inside
However, in rare cases, a tar.gz may unpack a large number of files directly into the current folder without creating a parent folder.
That’s why the next section’s tips—previewing the contents and choosing an extraction folder—are worth learning for safety and organization.
3. Common Extraction Patterns (Practical Commands You’ll Use Often)
Extracting a tar.gz file isn’t just “unpack everything.” In real-world use, you’ll often choose different approaches depending on the situation. Here are the most frequently used patterns.
3.1 Extract into the current directory (the basic default)
This is the most standard approach.
tar -xzvf sample.tar.gzIf you’re not sure where it extracted to, run ls in the same place you executed the command.
ls3.2 Extract into a specific folder (Desktop or a work folder)
If you want to control where files are extracted, use the -C option.
For example, to extract to your Desktop:
tar -xzvf sample.tar.gz -C ~/DesktopIf you want to extract into a dedicated work folder, do this:
mkdir -p ~/work
tar -xzvf sample.tar.gz -C ~/workThe key point is that the destination folder must already exist.
If it doesn’t, create it first using mkdir -p, then extract.
3.3 Preview the contents before extracting (recommended for safety)
“I’m afraid it will explode files everywhere if I extract it.”
“I’m not sure if it contains something weird or extracts into strange paths.”
In those cases, you can list the contents without extracting anything.
tar -tf sample.tar.gzIf you see something like this, you’re generally in good shape:
sample/sample/readme.txtsample/bin/...
On the other hand, if it looks like it will dump tons of files directly into the current directory, it’s safer to extract into a dedicated folder using -C.
3.4 If you’re not sure what format it really is, check with the file command
Even if the extension is .tar.gz, the actual content may be a different format (for example, due to a failed download).
In that case, use file to identify it:
file sample.tar.gzExample output (when it’s valid):
gzip compressed data ...
This one quick check can prevent a lot of pointless errors.
4. Extracting via GUI (Ubuntu’s Default File Manager)
If you’re not comfortable with Terminal yet, you can also extract tar.gz files using Ubuntu’s GUI (mouse-based) workflow.
Especially when you “just want to unpack it quickly,” the GUI can feel more intuitive and less stressful.
4.1 Step-by-step: extract via right-click (beginner-friendly)
Ubuntu’s default file manager (Files / Nautilus) can handle tar.gz archives.
- Open the file manager
- Find your
*.tar.gzfile (often in Downloads) - Right-click the file
- Choose one of the following from the menu
- Extract Here
- Extract To…
In most cases, Extract Here is perfectly fine to start with.
4.2 “Extract Here” vs “Extract To…”
The concept is the same as Terminal extraction:
- Extract Here
→ extracts into the folder you’re currently viewing - Extract To…
→ lets you choose a location like Desktop or a work folder
If the archive contains a lot of files, it’s a good idea to create a dedicated work folder and extract into it, so your Desktop (or Downloads) doesn’t get cluttered.
4.3 Pros and cons of GUI extraction
The GUI is convenient, but it has strengths and limitations.
Pros
- No commands to memorize
- Less chance of typos (so fewer input mistakes)
- Beginner-friendly and quick to use
Cons
- Harder to control the details of extraction
(e.g., extract only specific files, check logs) - Less useful error information
(Terminal output is usually clearer for troubleshooting)
If you use Linux regularly or do development work, it’s worth learning Terminal-based extraction eventually—it gives you more control when you need it.
5. Advanced: Extract Only Specific Files (Grab What You Need)
Normally, you extract everything from a tar.gz archive. However, in some cases, you may want to pull out only specific files.
- You only need one file from a large archive
- You want to check a config file or README first
- You don’t want to waste time extracting everything
This is where “extracting only specific files” becomes useful.
5.1 First, preview the contents (list files without extracting)
It’s hard to extract a specific file if you don’t know the exact path, so start by listing the contents.
tar -tf sample.tar.gzLook at the output paths (file names and folder structure) and identify the file you want to extract.
For example, you might see something like this:
sample/README.mdsample/config/default.confsample/bin/tool
5.2 Basic syntax: extract only a specific file
Once you know the exact file path, you can extract it like this:
tar -xzvf sample.tar.gz sample/README.mdIn this example, only sample/README.md will be extracted.
Tip: It’s safest to copy the path exactly as shown by
tar -tf.
5.3 You can also extract an entire folder inside the archive
Sometimes you don’t want just one file—you want everything under a specific folder.
Example: extract only sample/config/ and its contents
tar -xzvf sample.tar.gz sample/config/This extracts only the files inside the config folder.

5.4 Why this matters: extracting unnecessary files can cause problems
A common beginner mistake is extracting everything without thinking, which can lead to issues like:
- Your work folder becomes messy
- You lose track of where things are
- Files with similar names get overwritten
Once you get used to the workflow of “preview first, then extract only what you need,” Ubuntu file handling becomes much easier and safer.
6. Common Errors and Fixes (Troubleshooting Checklist)
Extracting tar.gz files is usually simple, but in real use, you may still run into errors.
This section covers the most common problems Ubuntu beginners face, using a clear “Cause → Fix” approach.
6.1 tar: ...: Cannot open: No such file or directory (File not found)
Common causes
- You’re running the command in the wrong folder
- You typed the filename incorrectly (including uppercase/lowercase differences)
- You didn’t include the full extension
How to fix it
First, check your current location:
pwdThen check whether the file exists in that folder:
lsIf it’s in Downloads, move there:
cd ~/Downloads
lsFinally, run the command again with the correct filename:
tar -xzvf sample.tar.gz6.2 tar: This does not look like a tar archive (Not a tar archive)
Common causes
- The file extension is
.tar.gz, but the content is actually a different format - The download is corrupted (you saved an HTML error page instead)
- It’s really a zip file, but was renamed to tar.gz
How to fix it
Check the file type using this command:
file sample.tar.gzIf you see something like HTML document, the download likely failed.
In that case, re-download the file and try again.
6.3 gzip: stdin: not in gzip format (Not gzip-compressed)
Common causes
- It wasn’t actually
.tar.gz(it was.tar) - The
.gzpart isn’t really gzip format - The file is corrupted
How to fix it
Double-check the extension. If it’s a .tar file, remove -z and run:
tar -xvf sample.tarAlso, to confirm whether the file is corrupted, this check is useful:
file sample.tar.gz6.4 Permission denied (No permission to write)
Common causes
- You’re extracting into a system directory (e.g.,
/usr/localor/) - You don’t have write permission in the destination folder
- Permission issues with an external drive mount
Safe fix for beginners
The safest approach is to work under your home directory:
mkdir -p ~/work
tar -xzvf sample.tar.gz -C ~/workIf you truly must extract into an admin-only location, use sudo:
sudo tar -xzvf sample.tar.gz -C /usr/localHowever, beginners should avoid overusing sudo.
A safer workflow is: extract into your home folder first → move only what you need.
6.5 Extraction worked, but “I don’t know where the files went”
Common causes
- You didn’t know your current directory when extracting
- Too many files were unpacked and you lost track
How to fix it
First, confirm where you extracted:
pwdThen look for recently created files/folders:
ls -ltIf you want to avoid this situation entirely, specify an extraction folder from the beginning:
mkdir -p ~/work/extract
tar -xzvf sample.tar.gz -C ~/work/extract6.6 Filenames become garbled after extraction (mojibake)
If a tar.gz archive contains Japanese filenames, they may become garbled depending on your environment.
This can happen due to differences in character encoding used when the archive was created.
How to approach it
- Check whether your Ubuntu locale is set to UTF-8
- If it still won’t work, extract on another environment and then copy the files
Example command to check locale:
localeIn most cases, if you see something like LANG=ja_JP.UTF-8, you’re less likely to run into encoding issues.
7. How to Create a tar.gz File (Bonus: Useful for Packaging Too)
At this point, you should be comfortable extracting tar.gz files. But when you use Ubuntu regularly, you’ll also run into situations where you want to create a tar.gz archive, such as:
- Sending an entire folder as a single file
- Creating backups
- Organizing and storing multiple files together
So in this section, we’ll cover the basics of creating tar.gz archives as well.
7.1 Basic command: compress a folder into tar.gz
For example, if you want to compress a folder named myfolder, run:
tar -czvf myfolder.tar.gz myfolder/
Here’s what the options mean:
-c: create-z: use gzip compression-v: verbose output-f: specify the output file name
7.2 Compress multiple files together
You can also bundle multiple files and folders into a single archive.
tar -czvf backup.tar.gz file1.txt file2.txt config/This works even when you mix files and folders in the same command.
7.3 If you want to exclude files before compressing (concept only)
In real-world work, you may want to avoid including certain files in your archive, such as:
- Cache files
- Huge log files
- Temporary files
In those cases, you can use the --exclude option. But as a beginner, it’s often enough to simply:
- Collect only what you want to archive into a work folder
- Compress that folder into a tar.gz archive
This approach is simple and works well in most cases.
8. Summary: The Fastest Way to Extract tar.gz on Ubuntu
If you want the shortest path to extracting a tar.gz file on Ubuntu, this one command is enough in most cases:
tar -xzvf filename.tar.gzAnd if you want to avoid mistakes in real-world work, remember these three tips:
- Preview the contents first:
tar -tf filename.tar.gz - Choose an extraction folder:
tar -xzvf filename.tar.gz -C destination - Check the actual file type:
file filename.tar.gz
tar.gz archives show up everywhere on Ubuntu, so once you understand these basics, everyday work becomes much smoother.
FAQ (Frequently Asked Questions)
Q1. What is the easiest way to extract a tar.gz file on Ubuntu?
A. The most reliable method is to run this command in Terminal:
tar -xzvf filename.tar.gzQ2. Can I choose the destination folder when extracting?
A. Yes. Use the -C option to specify the extraction destination:
tar -xzvf sample.tar.gz -C ~/DesktopQ3. Can I preview the contents without extracting?
A. Yes. You can list the contents with this command:
tar -tf sample.tar.gzQ4. Can I extract tar.gz files using the GUI (right-click)?
A. Yes. In Ubuntu’s file manager, right-click the tar.gz file and select Extract Here to unpack it.
Q5. I get not a tar archive and it won’t extract
A. The file may be corrupted, or the extension may not match the actual file type. Check it with:
file sample.tar.gzQ6. I also want to know how to create a tar.gz file
A. To compress a folder into tar.gz format, use:
tar -czvf archive.tar.gz foldername/

