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!
- Rename a directory using Linux/Unix command
- ls command to list only directories
- How to Restart or Reload Nginx Server Service on Linux
- 3 ways to clear screen on Linux Terminal
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: sudo: unable to open Read-only file system
- Create Hidden File or Directory using Shell Command
- Command to know the installed Debian version?
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - bash: man: command not found
- How to tar.gz a directory or folder Command
- How to Display content of a file in Terminal Screen?
- How to change bash terminal prompt string and color
- Sort ls command by last modified date and time
- Execute .bin and .run file Ubuntu Linux
- zsh hello world example
- How to check uptime of Linux/Unix/macOS system/server using console command?
- [Fix] Linux - bash: useradd: command not found
- Command to check Last Login or Reboot History of Users and TTYs
- How to install and Configure sar sysstat tools in Ubuntu Linux
- How to use SCP Command to Copy Directory
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to connect to SSH port other than default 22
- Install OpenSSL on Linux/Ubuntu
- How to Print to stderr in Python - Python
- Java: The value of the local variable string is not used - Java
- How to Change Java JDK Version in IntelliJ IDE - Java
- Change the default diff or commit editor for git - Git
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager - Android
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end users experience - Java
- PowerShell For Each Loop Examples - Powershell
- Fix - zsh: command not found: conda [macOS] - zsh