Linux下wget命令的使用方法(linux命令wget)
The wget command is an important command line utility in Linux used to download files from the internet.It supports downloading files from HTTP, HTTPS, and FTP protocols.In this tutorial, let us explore how to use wget command for downloading files from the internet.
To download a single file with wget, use the following syntax:
wget
For example, to download a file from a URL http://example.com/ubuntu.iso, type the following command.
wget http://example.com/ubuntu.iso
If you want to download a file to a specified directory, use the -P option as shown below.
wget -P /opt/downloads http://example.com/ubuntu.iso
The above command will download the file ubuntu.iso to the /opt/downloads directory.
To download a file from FTP servers, use the following syntax.
wget -ftp
If you get an error message “Unknown syntax ‘ftp'” when using the above command, make sure you have installed the ftp module on your system.
To specify a username and password when downloadling files from a FTP server, use the following command.
wget –ftp-user= –ftp-password= ftp://ftp.example.com/file.zip
You can also specify the maximum download and upload speed for wget by using the following command.
wget –limit-rate= –upload-rate= url
To download a file in the background, use the -b option.
wget -b http://example.com/ubuntu.iso
The above command will start downloading the ubuntu.iso file in the background.
To print the timestamp of the last modified/retrieved file while downloading files, use the -t switch as shown below.
wget -t
The wget command can be used to download multiple files at a time. To download multiple files, simply list the URLs of the files in a text file and use the -i option to specify the name of the text file.
For example, if you have a file named urls.txt containing 3 URLs, use the following command.
wget -i urls.txt
The above command will download the files from all the 3 URLs listed in the urls.txt file.
To enable FTP passive mode, use the –ftp-pasv switch.
wget –ftp-pasv
This will enable passive mode for FTP downloads.
The wget command is a powerful command line utility for downloading files from the internet.In this tutorial, we have explored the basic usage of the wget command.For more information and advanced usage, refer to the official wget manual.