Tar (Tape Archive) is a popular file archiving format in Linux. It can be used together with gzip (tar.gz) or bzip2 (tar.bz2) for compression. It is the most widely used command line utility to create compressed archive files (packages, source code, databases and so much more) that can be transferred easily from machine to another or over a network.
What is a Tar GZ file? Source code is often packed for download as a TAR (Tape ARchive) file, that is a standard format in the Unix/Linux world. These files have a.tar extension; they can also be compressed, the extension is.tar.gz or.tar.bz2 in these cases. There are several ways to unpack these files. $ tar xvfj file.tar or $ tar xvfj file.tar -C path of file in directoy. Untar multiple.tar,.tar.gz,.tar.tbz file in Linux: This command will extract or untar multiple files from the tar, tar.gz and tar.bz2 archive file. For example the above command will extract “fileA” “fileB” from the archive files.
Read Also: 18 Tar Command Examples in Linux
In this article, we will show you how to download tar archives using two well known command line downloaders – wget or cURL and extract them with one single command.
How to Download and Extract File Using Wget Command
The example below shows how to download, unpack the latest GeoLite2 Country databases (use by the GeoIP Nginx module) in the current directory.
The wget option -O
specifies a file to which the documents is written, and here we use -
, meaning it will written to standard output and piped to tar and the tar flag -x
enables extraction of archive files and -z
decompresses, compressed archive files created by gzip.
To extract tar files to specific directory, /etc/nginx/ in this case, include use the -C
flag as follows.
Note: If extracting files to particular directory that requires root permissions, use the sudo command to run tar.
Download and Extract File to Directory
Alternatively, you can use the following command, here, the archive file will be downloaded on your system before you can extract it.
To extract compressed archive file to a specific directory, use the following command.
How to Download and Extract File Using cURL Command
Considering the previous example, this is how you can use cURL to download and unpack archives in the current working directory.
To extract file to different directory while downloading, use the following command.
That’s all! In this short but useful guide, we showed you how to download and extract archive files in one single command. If you have any queries, use the comment section below to reach us.
The Linux “tar” stands for tape archive, which is used by large number of Linux/Unix system administrators to deal with tape drives backup. The tar command used to rip a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux. The tar is most widely used command to create compressed archive files and that can be moved easily from one disk to another disk or machine to machine.
In this article we will be going to review and discuss various tar command examples including how to create archive files using (tar, tar.gz and tar.bz2) compression, how to extract archive file, extract a single file, view content of file, verify a file, add files or directories to archive file, estimate the size of tar archive file, etc.
The main purpose of this guide is to provide various tar command examples that might be helpful for you to understand and become expert in tar archive manipulation.
1. Create tar Archive File
The below example command will create a tar archive file tecmint-14-09-12.tar for a directory /home/tecmint in current working directory. See the example command in action.
Let’s discuss each option that we have used in the above command for creating a tar archive file.
- c – Creates a new .tar archive file.
- v – Verbosely show the .tar file progress.
- f – File name type of the archive file.
2. Create tar.gz Archive File
To create a compressed gzip archive file we use the option as z. For example the below command will create a compressed MyImages-14-09-12.tar.gz file for the directory /home/MyImages. (Note : tar.gz and tgz both are similar).
3. Create tar.bz2 Archive File
The bz2 feature compress and create archive file less than the size of the gzip. The bz2 compression takes more time to compress and decompress files as compared to gzip which takes less time. To create highly compressed tar file we use option as j. The following example command will create a Phpfiles-org.tar.bz2 file for a directory /home/php. (Note: tar.bz2 and tbz is similar as tb2).
4. Untar tar Archive File
To untar or extract a tar file, just issue following command using option x (extract). For example the below command will untar the file public_html-14-09-12.tar in present working directory. If you want to untar in a different directory then use option as -C (specified directory).
5. Uncompress tar.gz Archive File
To Uncompress tar.gz archive file, just run following command. If would like to untar in different directory just use option -C and the path of the directory, like we shown in the above example.
6. Uncompress tar.bz2 Archive File
To Uncompress highly compressed tar.bz2 file, just use the following command. The below example command will untar all the .flv files from the archive file.
7. List Content of tar Archive File
To list the contents of tar archive file, just run the following command with option t (list content). The below command will list the content of uploadprogress.tar file.
8. List Content tar.gz Archive File
Use the following command to list the content of tar.gz file.
9. List Content tar.bz2 Archive File
To list the content of tar.bz2 file, issue the following command.
10. Untar Single file from tar File
To extract a single file called cleanfiles.sh from cleanfiles.sh.tar use the following command.
11. Untar Single file from tar.gz File
To extract a single file tecmintbackup.xml from tecmintbackup.tar.gz archive file, use the command as follows.
12. Untar Single file from tar.bz2 File
To extract a single file called index.php from the file Phpfiles-org.tar.bz2 use the following option.
13. Untar Multiple files from tar, tar.gz and tar.bz2 File
To extract or untar multiple files from the tar, tar.gz and tar.bz2 archive file. For example the below command will extract “file 1” “file 2” from the archive files.
14. Extract Group of Files using Wildcard
To extract a group of files we use wildcard based extracting. Power peavey cs 800x cocok untuk speaker berapa inch. For example, to extract a group of all files whose pattern begins with .php from a tar, tar.gz and tar.bz2 archive file.
15. Add Files or Directories to tar Archive File
To add files or directories to existing tar archived file we use the option r (append). For example we add file xyz.txt and directory php to existing tecmint-14-09-12.tar archive file.
16. Add Files or Directories to tar.gz and tar.bz2 files
The tar command don’t have a option to add files or directories to an existing compressed tar.gz and tar.bz2 archive file. If we do try will get the following error.
17. How To Verify tar, tar.gz and tar.bz2 Archive File
To verfify any tar or compressed archived file we use option as W (verify). To do, just use the following examples of command. (Note : You cannot do verification on a compressed ( *.tar.gz, *.tar.bz2 ) archive file).
18. Check the Size of the tar, tar.gz and tar.bz2 Archive File
To check the size of any tar, tar.gz and tar.bz2 archive file, use the following command. For example the below command will display the size of archive file in Kilobytes (KB).
Tar Usage and Options
- c – create a archive file.
- x – extract a archive file.
- v – show the progress of archive file.
- f – filename of archive file.
- t – viewing content of archive file.
- j – filter archive through bzip2.
- z – filter archive through gzip.
- r – append or update files or directories to existing archive file.
- W – Verify a archive file.
- wildcards – Specify patterns in unix tar command.
That’s it for now, hope the above tar command examples are enough for you to learn and for more information please use man tar command.
If you are looking to split any large tar archive file into multiple parts or blocks, just go through this article:
Don’t Miss:Split Large ‘tar’ Archive into Multiple Files of Certain Size
If we’ve missed any example please do share with us via comment box and please don’t forget to share this article with your friends. This is the best way to say thanks….