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.
Have Questions? Post them here!
- [Fix] Linux - bash: useradd: command not found
- Calculate days between dates using dateutils ddiff command
- pwd Command - Print Working Directory
- Rename a directory using Linux/Unix command
- How to go to the End of File in Nano Editor
- How to tar.gz a directory or folder Command
- How to remove/delete a directory in Linux/macOs
- How to Display content of a file in Terminal Screen?
- ls command sort by file size [Linix/UNIX/macOS/bash]
- How to Copy Entire Directory to another Directory in Linux
- 3 ways to clear screen on Linux Terminal
- Command to check Last Login or Reboot History of Users and TTYs
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to backup a file in Linux/Unix
- Command to know the installed Debian version?
- Check SSH/OpenSSH version Command
- 3 Commands to stop Nginx Server
- Linux: Create a New User and Password and Login Example
- How to install npm on Ubuntu
- How to List All Users in Linux
- How to Get the List of Shells on Linux
- Fix - ssh-copy-id no identities found error
- Installing and using unzip Command to unzip a zip file using Terminal
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- zsh hello world example
- How to make div or text in html unselectable using CSS - CSS
- Notepad++ Mark and Copy feature - NotepadPlusPlus
- Access URL for SharePoint Tenant Admin Center (Online Office 365) - SharePoint
- 5 Programming Languages to Learn in the Year 2021 - News
- Calculate Area of Trapezoid - C-Program
- Android Developers Bluetooth Tutorial - Android
- [Solution] Java JDBC SQLException: No value specified for parameter 1 - Java
- 25 Notepad++ Command Argument List - NotepadPlusPlus