
- Operating System Tutorial
- OS - Home
- OS - Overview
- OS - Components
- OS - Types
- OS - Services
- OS - Properties
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling algorithms
- OS - Multi-threading
- OS - Memory Management
- OS - Virtual Memory
- OS - I/O Hardware
- OS - I/O Software
- OS - File System
- OS - Security
- OS - Linux
- OS - Exams Questions with Answers
- OS - Exams Questions with Answers
- Operating System Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
How to Download and Extract Tar Files with One Command in Linux
We can download any required file form the web using the linux terminal. But many times it is found that the downloaded file is a zipped file which is in tar format. In this article we will see how to download and extract the file in a single command.
Using wget and tar
The wget command downloads the data form the given URL while the tar command does the extraction of the tar.gz files.
$ wget -c https://www.metoffice.gov.uk/hadobs/hadisd/v300_2018f/data/WMO_200000-249999.tar.gz -O - | sudo tar -xz
Running the above code gives us the following result:
--2020-01-01 07:25:18-- https://www.metoffice.gov.uk/hadobs/hadisd/v300_2018f/data/WMO_200000-249999.tar.gz Resolving www.metoffice.gov.uk (www.metoffice.gov.uk)... 104.80.55.230 Connecting to www.metoffice.gov.uk (www.metoffice.gov.uk)|104.80.55.230|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 454079101 (433M) [application/x-gzip] Saving to: ‘STDOUT’ - 100%[================================================================================>] 433.04M 4.23MB/s in 1m 46s 2020-01-01 07:27:04 (4.10 MB/s) - written to stdout [454079101/454079101]
Next we list the extracted files to verify the result.
$ ls -lrt
Running the above code gives us the following result −
total 500040 -rw-r--r-- 1 10013 users 948807 Jan 26 2019 hadisd.3.0.0.2018f_19310101-20190101_200660-99999.nc.gz -rw-r--r-- 1 10013 users 1296563 Jan 26 2019 hadisd.3.0.0.2018f_19310101-20190101_200490-99999.nc.gz -rw-r--r-- 1 10013 users 2298004 Jan 26 2019 hadisd.3.0.0.2018f_19310101-20190101_200460-99999.nc.gz ……. ……..
Using curl
We can also use curl in place of wget in the above example. Again it is a single command.
$ sudo curl https://www.metoffice.gov.uk/hadobs/hadisd/v300_2018f/data/WMO_200000-249999.tar.gz | sudo tar -xz
Running the above code gives us the following result:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 433M 100 433M 0 0 5217k 0 0:01:24 0:01:24 --:--:-- 5370k
Next we list the extracted files to verify the result.
$ ls -lrt
Running the above code gives us the following result −
total 500040 -rw-r--r-- 1 10013 users 948807 Jan 26 2019 hadisd.3.0.0.2018f_19310101-20190101_200660-99999.nc.gz -rw-r--r-- 1 10013 users 1296563 Jan 26 2019 hadisd.3.0.0.2018f_19310101-20190101_200490-99999.nc.gz -rw-r--r-- 1 10013 users 2298004 Jan 26 2019 hadisd.3.0.0.2018f_19310101-20190101_200460-99999.nc.gz ……. ……..
- Related Articles
- The best way to compress and extract files using the tar command on linux
- Linux tar Command
- Find and tar Files on Linux
- How to swap two files in Linux command line?
- How to download APK files from Google Play Store on Linux
- How to download all pdf files with selenium python?
- How to compare the files available in two directories using diff command in Linux?
- Convert XLSX to CSV in Linux with Command Line in Linux
- How to use a pipe with Linux find command?
- How to download large files through PHP script?
- How to download SRT files of YouTube Videos?
- How are files added to a tar file using Python?
- md5sum Command in Linux with Examples
- Working with Zip Command in Linux
- Move all files except one on Linux
