How wget realizes download and decompression
How wget realizes download and decompression, GNU Wget is a command-line program for downloading files from Web sites
GNU Wget is a command-line program for downloading files from Web sites. Wget allows you to download files using HTTP, HTTPS and FTP protocols.
The wget command offers many options that allow you to download multiple files, resume downloads, limit speed, download recursively, download in the background, mirror websites, and more.
The wget command is now pre-installed on most Linux distributions, to check if the system has wget installed. Please press the shortcut key CTRL+ALT+T
to open the terminal and run the command wget
.
Install wget
If wget is installed, the terminal prints the error message wget: missing URL, otherwise prints the message wget command not found.
If your computer is running a Debian-based Linux distribution. Such as Linux mint, Ubuntu. Please run the command sudo apt install wget
to install wget.
If your computer is running a RedHat-based Linux distribution. For example CentOS, Fedora. Please run the command sudo yum install wget
to install wget.
sudo apt install wget
sudo yum install wget
wget download and decompress
This is an advanced trick that saves time and allows you to unzip while downloading. Do whatever you want besides decompressing, as long as the command on the right side of the pipe allows reading from standard input .
To decompress while downloading, you need to use the wget command -q option to close the standard output of the download status, and then use the wget command -O option in combination to specify the standard output as a file.
When using the hyphen - as the file in wget, the standard output is used as the file written, and finally passed to the tar command through the pipe |.
tar extracts the file downloaded by the wget command to the specified directory. The -C option specifies the target directory for writing, and the parameter - option means to read data from standard input.
wget -q -O - "http://wordpress.org/latest.tar.gz" | tar -xzf - -C /var/www
This trick is to use the standard output of the process and the pipe symbol of the Shell to combine the commands into an advanced skill.
We have also said in another tutorial before: standard input/standard output/standard error and redirection what is standard output and redirected standard output.
You can use these file descriptors to control the input and output of command programs or scripts. to create some advanced operations. Because they are the backbone of shell scripts or programs.