If you move to the Linux Dististituions such as Ubuntu or Fedora, or the macOS for Mac and Macbook, it's often that you will come across .tar.gz files, and will make you wonder "How do I open this tar.gz file?
The tar command
It is a General User Command that you can find at location /usr/bin/tar. Using this command you can archive or unarchive files.
How to untar a tar.gz file?
-
There are two options or flags that you need to make use of with tar, -x (--extract) and -f (--file) to extract it,
# tar -xf data-file.tar.gz
As you can see the myDir is the extracted directory that was created using tar -xf command,
# ls -l total 8 -rw-r--r-- 1 root root 213 Nov 5 10:24 data-file.tar.gz drwxr-xr-x 2 root root 4096 Nov 5 10:23 myDir # tree -L 2 myDir/ myDir/ |-- data.txt |-- insurance.xlsx |-- sales-report-2022.xlsx `-- sales.csv 0 directories, 4 files
Troubleshooting
-
If you get an error "bash: tar: command not found", then on you do not have the tar package installed on your system. You will need to make use of a Package manager to get it installed first.
For Ubuntu:
sudo apt-get tar
For Alpine Linux:
apk get tar
For Amazon Linux:
yum install tar
Note that the order of options matter, -xf, if you provide -fx you will get an error,
# tar -fx data-file.tar.gz tar: You must specify one of the `-Acdtrux' or `--test-label' options Try `tar --help' or `tar --usage' for more information.
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
- How to Parse XML String in Python - Python
- Online Tool to Sort Data Alphabetical (Ascending/Descending) - Tools
- [Solution] IDEA IntelliJ System.out.println function shortcut (sysout alternative for eclipse IDE) - HowTos
- Python Sleep Function/Method Code Example - Python
- Python: Read a file into a List - Python
- How to check for Updates on Windows 11 - Windows-11
- How to install homebrew (brew) on M1 Mac - MacOS
- AlertDialog with no buttons (just text message) - Android