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
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.
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.
Have Questions? Post them here!
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to create tar.gz file using Terminal Command
- How to List All Users in Linux
- How to check file permissions for your file using Linux/Unix/macOS Terminal Command
- How to exit from nano command
- How to go to the End of File in Nano Editor
- ls command sort by file size [Linix/UNIX/macOS/bash]
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- How to tar.gz a directory or folder Command
- Linux: Create a New User and Password and Login Example
- How to install npm on Ubuntu
- Create and write file in single Linux/macOS command
- 3 ways to clear screen on Linux Terminal
- How to ls command to output one entry per line [macOS/Linux/Bash]
- Execute .bin and .run file Ubuntu Linux
- How to install and Configure sar sysstat tools in Ubuntu Linux
- Fix - ssh-copy-id no identities found error
- Terminal display next month Calendar
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- Fix - bash: man: command not found
- How to install curl on Alpine Linux
- Command to unzip or extract tar.gz file on Linux or macOS?
- How to Display content of a file in Terminal Screen?
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- [Fix] Docker Error response from daemon: manifest for :latest not found: manifest unknown - Docker
- Display Safari URL address link on hover - MacOS
- How to change TextView or EditText Text Color on Focus and on Press - Android
- Installing brew on M1/M2 ARM Mac - MacOS
- Robinhood unexpected server error - Android
- Toast not getting displayed Android App - Android
- Fetch as Google Crawl Error or Redirected Status - Google
- Create a Zip file using Java Code programmatically - Java