linux wget 命令
In this tutorial, let’s learn how to download a file using the wget command in Linux. For any Linux user, downloading files is a frequent task. While you can download things using your browser, it is helpful to know the steps to download a file in Linux using the command line. this is where the wget command comes into the picture.
在本教程中,让我们学习如何在Linux中使用wget命令下载文件。 对于任何Linux用户,下载文件都是一项常见的任务。 虽然可以使用浏览器下载内容,但了解使用命令行在Linux中下载文件的步骤会很有帮助。 这是wget命令进入图片的地方。
The wget utility comes pre-installed in most Linux distributions. However, if it is not the case for your system, you can download it using the package manager for your distribution.
wget实用程序预先安装在大多数Linux发行版中。 但是,如果不是您的系统,则可以使用软件包管理器进行下载以进行分发。
To check this, we will ask the system to display the version of the wget command. This can be done by typing this in your terminal.
为了检查这一点,我们将要求系统显示wget命令的版本。 可以通过在终端中键入此命令来完成。
wget --version
If this does not show you the version of wget command on your system, you need to install it. Before we begin to install wget command in Linux, we need to make sure that all our system repositories are up-to-date.
如果未在系统上显示wget命令的版本,则需要安装它。 在开始在Linux中安装wget命令之前,我们需要确保所有系统信息库都是最新的。
To do this, we need to update our default repositories using the apt package management service. Open the command line on your system and type the following.
为此,我们需要使用apt软件包管理服务更新默认存储库。 在系统上打开命令行,然后键入以下内容。
sudo apt update
Now, you can install the wget command on your system depending on the distribution you are using.
现在,您可以根据所使用的发行版在系统上安装wget命令。
For Debian and Ubuntu-based systems, use the following command.
对于基于Debian和Ubuntu的系统,请使用以下命令。
sudo apt install wget
For CentOS and Fedora-based systems, use the following command.
对于基于CentOS和Fedora的系统,请使用以下命令。
sudo yum install wget
The wget command in Linux is a command used to download files from the web. This command uses the URL of a file to download it. The command can be used to download data over HTTP, FTP, and HTTPS protocols.
Linux中的wget命令是用于从Web下载文件的命令。 此命令使用文件的URL进行下载。 该命令可用于通过HTTP,FTP和HTTPS协议下载数据。
We can use this to directly download files from our command line without needing a web browser. Further, wget is a non-interactive utility.
我们可以使用它直接从命令行下载文件,而无需Web浏览器。 此外,wget是非交互式实用程序。
This enables a user to download a file in the background. It can work even when a user is has logged off. This is highly important in an instance when you are downloading a large file.
这使用户可以在后台下载文件。 即使用户已注销,它也可以工作。 这在下载大文件的实例中非常重要。
In case the download fails, the wget utility will repeatedly try to resume it till the complete file has been downloaded. If the server allows, it will continue the download from the last point where it left off.
如果下载失败,则wget实用程序将反复尝试恢复它,直到下载完整的文件为止。 如果服务器允许,它将从上次停止的地方继续下载。
The best way to understand any command is through understanding it’s syntax. Here is how the syntax for the wget command in Linux looks like.
理解任何命令的最佳方法是通过了解其语法。 这是Linux中wget命令的语法。
wget [option] [URL]
Here, we use the URL of the file which we wish to download. The wget utility allows several options to set up our download. Here is a list with some of the commonly used options offered by the wget command in Linux.
在这里,我们使用要下载的文件的URL。 wget实用程序允许使用几个选项来设置我们的下载。 这是Linux中wget命令提供的一些常用选项的列表。
Option | Effect |
-h | This option is used to display the help message for the wget command. It includes all the possible options which can be used with the wget command in Linux |
-b | This option is used to send the download process to the background as soon as it is initiated with the wget command. It frees up your terminal session to run other commands. |
-i | This option is used to read the URL for the wget command from a file. It eliminates the need for the wget command to have an URL and allows the inclusion of an input file. |
-o | Name of the output file if you do not want the same name as the server has provided |
-c | This tag makes wget keep a track of the download progress in case of download interruptions. We can continue an interrupted download if this option was used when the download was initiated. |
-tries=n | This option is used to limit the number of tries for the wget command. Using this command will cause the wget utility to retry a download only ‘n’ times. The default is 20. |
-limit-rate=maxlim | This option is used to limit the download speed for the wget command. This helps the user to dictate the amount of bandwidth to be allocated for a download. |
选项 | 影响 |
-H | 此选项用于显示wget命令的帮助消息。 它包括可与Linux中的wget命令一起使用的所有可能选项。 |
-b | 此选项用于使用wget命令启动下载过程后立即将其发送到后台。 它释放了您的终端会话以运行其他命令。 |
-一世 | 此选项用于从文件读取wget命令的URL。 它消除了wget命令具有URL的需要,并允许包含输入文件。 |
-o | 如果您不想使用与服务器提供的名称相同的输出文件的名称 |
-C | 如果下载中断,此标签可使wget跟踪下载进度。 如果启动下载时使用了此选项,我们可以继续中断下载。 |
-tries = n | 此选项用于限制wget命令的尝试次数。 使用此命令将导致wget实用程序仅重试一次'n'次。 默认值为20。 |
-极限速率=最大极限 | 此选项用于限制wget命令的下载速度。 这有助于用户确定要分配用于下载的带宽量。 |
While this list covered the basic options used in the wget utility. You should explore the help page by using the -h option to understand the full potential of the wget command.
该列表涵盖了wget实用程序中使用的基本选项。 您应该使用-h选项来浏览帮助页面,以了解wget命令的全部功能。
Now we have developed an understanding of the wget command in Linux and its parameters. Now it’s time to use this knowledge to download files using the wget command. For this tutorial, we will go over a couple of examples.
现在,我们已经了解了Linux中的wget命令及其参数。 现在是时候使用这些知识通过wget命令下载文件了。 对于本教程,我们将介绍一些示例。
The simplest use of the wget utility is to download a single file. For this example, we will download an iso file.
wget实用程序最简单的用法是下载一个文件。 对于此示例,我们将下载一个iso文件。
wget -c
Wget Download Iso Wget下载Iso
In the above example, I’m downloading the Kali Linux ISO file for demonstration along with the -c tag. Since this is a pretty large file, if the ISO file download is interrupted for any reason, I can run the same command in the same directory and the download will continue from where it left off.
在上面的示例中,我正在下载Kali Linux ISO文件以及-c标记进行演示。 由于这是一个很大的文件,如果由于任何原因中断了ISO文件下载,我可以在同一目录中运行相同的命令,下载将从中断处继续。
You don’t need to connect to an FTP server using the ftp command to download files. This can be done while using the wget utility. The difference between downloading a file from HTTP vs an FTP server is the possibility that there’s a username and password requirement.
您无需使用ftp命令连接到FTP服务器即可下载文件。 这可以在使用wget实用程序时完成。 从HTTP下载文件与FTP服务器下载文件的区别在于,可能需要输入用户名和密码。
Let’s use the wget command to login to the FTP server and download a file.
让我们使用wget命令登录到FTP服务器并下载文件。
wget --user='FTP username' --password='FTP server password'
Ftp Connection ftp连接
As you can see in the above image, I have connected to one of the free FTP servers on the internet with their demo username and password. The highlighted section shows that the login was successful.
如上图所示,我已使用其演示用户名和密码连接到Internet上的免费FTP服务器之一。 突出显示的部分显示登录成功。
The wget command in Linux is a useful tool to download files from the web without having to leave the command line. Its appealing features and robust functionality is the reason behind its popularity amongst Linux users, from beginners to veterans.
Linux中的wget命令是一个有用的工具,可以从Web下载文件而无需离开命令行。 它吸引人的功能和强大的功能是其在Linux用户(从初学者到资深人士)中受欢迎的原因。
We hope this tutorial was able to help you understand the wget command in Linux. We discussed only the basic usage of the wget command in this tutorial, so make sure to explore the command on your own.
我们希望本教程能够帮助您了解Linux中的wget命令。 在本教程中,我们仅讨论了wget命令的基本用法,因此请确保自己探索该命令。
If you have any feedback, queries, or suggestions, feel free to reach out to us in the comments below.
如果您有任何反馈,疑问或建议,请随时通过以下评论与我们联系。
翻译自: https://www.journaldev.com/39630/wget-command-in-linux
linux wget 命令