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.gzAs 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 tarFor Alpine Linux:
apk get tarFor Amazon Linux:
yum install tarNote 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.
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!