侧边栏壁纸
Linux入门自学网博主等级

每日学一条Linux命令,终成Linux大神

  • 累计撰写 725 篇文章
  • 累计创建 143 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Linux axel命令教程:如何使用多线程下载工具提高下载速度(附实例教程和注意事项)

Linux axel命令介绍

axel是一个轻量级的多线程下载工具,它可以利用多个连接同时从一个或多个源下载文件,从而提高下载速度和效率。axel支持HTTP,HTTPS和FTP协议,也支持断点续传和镜像选择。axel的名字来源于一个动画片《未来警察》中的一个角色,他是一个速度极快的赛车手。

Linux axel命令适用的Linux版本

axel命令可以在大多数Linux发行版中使用,但是有些发行版可能没有预装axel,需要手动安装。以下是一些常见的Linux发行版中安装axel的方法:

  • Debian/Ubuntu/Mint等基于Debian的发行版,可以使用apt-get命令安装axel:
[linux@bashcommandnotfound.cn ~]$ sudo apt-get update
[linux@bashcommandnotfound.cn ~]$ sudo apt-get install axel
  • RedHat/CentOS/Fedora等基于RedHat的发行版,可以使用yum或dnf命令安装axel:
[linux@bashcommandnotfound.cn ~]$ sudo yum install axel

或者

[linux@bashcommandnotfound.cn ~]$ sudo dnf install axel
  • Arch/Manjaro等基于Arch的发行版,可以使用pacman命令安装axel:
[linux@bashcommandnotfound.cn ~]$ sudo pacman -S axel
  • Gentoo等基于Gentoo的发行版,可以使用emerge命令安装axel:
[linux@bashcommandnotfound.cn ~]$ sudo emerge axel

Linux axel命令的基本语法

axel命令的基本语法格式如下:

axel [选项]... [URL]...

其中,URL是要下载的文件的地址,可以是一个或多个,也可以是一个包含URL的文件。选项是用来控制axel行为的参数,可以有多个,也可以没有。

Linux axel命令的常用选项或参数说明

axel命令有很多选项或参数,可以用来调整下载的细节,如线程数,输出文件名,超时时间,用户代理等。以下是一些常用的选项或参数的说明:

选项或参数说明
-a, --alternate使用备用进度条
-c, --continue继续未完成的下载
-h, --help显示帮助信息
-n, --num-connections=NUM指定最大连接数,默认为4
-o, --output=FILE指定输出文件名
-q, --quiet不显示进度条和错误信息
-s, --search[=NUM]搜索镜像站点,可指定最大数量,默认为0
-v, --version显示版本信息

Linux axel命令的实例

以下是一些使用axel命令的实例,可以帮助你更好地理解和使用axel命令。

实例1:使用axel下载一个文件

如果你只想下载一个文件,你可以直接输入axel命令后跟上文件的URL,如:

[linux@bashcommandnotfound.cn ~]$ axel http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
File size: 44606216 bytes
Opening output file emacs-27.2.tar.xz
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished

Downloaded 42.5 megabytes in 7 seconds. (6028.57 KB/s)

这样,axel会使用默认的4个连接来下载文件,并保存为和URL中相同的文件名。

实例2:使用axel继续未完成的下载

如果你之前下载了一部分文件,但是由于某些原因中断了,你可以使用-c或--continue选项来继续下载,如:

[linux@bashcommandnotfound.cn ~]$ axel -c http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
File size: 44606216 bytes
Opening output file emacs-27.2.tar.xz
State file found: 20971520 bytes downloaded, 23634696 to go.
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished

Downloaded 22.5 megabytes in 4 seconds. (5818.75 KB/s)

这样,axel会从上次中断的地方继续下载,直到完成。

实例3:使用axel指定输出文件名

如果你想下载的文件保存为一个不同的文件名,你可以使用-o或--output选项来指定输出文件名,如:

[linux@bashcommandnotfound.cn ~]$ axel -o myemacs.tar.xz http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
File size: 44606216 bytes
Opening output file myemacs.tar.xz
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished

Downloaded 42.5 megabytes in 7 seconds. (6028.57 KB/s)

这样,axel会下载文件并保存为myemacs.tar.xz。

实例4:使用axel指定最大连接数

如果你想调整下载的连接数,你可以使用-n或--num-connections选项来指定最大连接数,如:

[linux@bashcommandnotfound.cn ~]$ axel -n 8 http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
File size: 44606216 bytes
Opening output file emacs-27.2.tar.xz
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished
Connection 4 finished
Connection 5 finished
Connection 6 finished
Connection 7 finished

Downloaded 42.5 megabytes in 5 seconds. (8490.00 KB/s)

这样,axel会使用8个连接来下载文件,可能会提高下载速度,但也可能会增加服务器的负担。

实例5:使用axel搜索镜像站点

如果你想下载的文件有多个镜像站点,你可以使用-s或--search选项来搜索镜像站点,如:

[linux@bashcommandnotfound.cn ~]$ axel -s 5 http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
File size: 44606216 bytes
Opening output file emacs-27.2.tar.xz
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished
Connection 4 finished
...

实例6:使用axel下载多个文件

如果你想一次下载多个文件,你可以在axel命令后跟上多个URL,用空格隔开,如:

[linux@bashcommandnotfound.cn ~]$ axel http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.gz
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
File size: 44606216 bytes
Opening output file emacs-27.2.tar.xz
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished

Downloaded 42.5 megabytes in 7 seconds. (6028.57 KB/s)
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.gz
File size: 63342592 bytes
Opening output file emacs-27.2.tar.gz
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished

Downloaded 60.4 megabytes in 10 seconds. (6040.00 KB/s)

这样,axel会依次下载每个URL指定的文件,并保存为和URL中相同的文件名。

实例7:使用axel从一个文件中读取URL

如果你有一个文件,里面包含了多个要下载的文件的URL,每行一个,你可以使用-s或--search选项来指定这个文件,如:

[linux@bashcommandnotfound.cn ~]$ cat urls.txt
http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.gz
[linux@bashcommandnotfound.cn ~]$ axel -s urls.txt
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
File size: 44606216 bytes
Opening output file emacs-27.2.tar.xz
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished

Downloaded 42.5 megabytes in 7 seconds. (6028.57 KB/s)
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.gz
File size: 63342592 bytes
Opening output file emacs-27.2.tar.gz
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished

Downloaded 60.4 megabytes in 10 seconds. (6040.00 KB/s)

这样,axel会从urls.txt文件中读取每个URL,并依次下载每个文件。

实例8:使用axel不显示进度条和错误信息

如果你想让axel在下载时不显示进度条和错误信息,只显示最终的结果,你可以使用-q或--quiet选项,如:

[linux@bashcommandnotfound.cn ~]$ axel -q http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
Downloaded 42.5 megabytes in 7 seconds. (6028.57 KB/s)

这样,axel会静默地下载文件,并只显示下载的总大小和速度。

实例9:使用axel使用备用进度条

如果你想让axel在下载时使用备用进度条,即用点号表示下载的进度,你可以使用-a或--alternate选项,如:

[linux@bashcommandnotfound.cn ~]$ axel -a http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
Initializing download: http://mirrors.ustc.edu.cn/gnu/emacs/emacs-27.2.tar.xz
File size: 44606216 bytes
Opening output file emacs-27.2.tar.xz
Starting download

...............................................

Downloaded 42.5 megabytes in 7 seconds. (6028.57 KB/s)

这样,axel会使用点号来表示下载的进度,每个点号表示一个连接下载的一部分。

实例10:使用axel显示帮助信息和版本信息

如果你想查看axel的帮助信息,即所有可用的选项或参数的说明,你可以使用-h或--help选项,如:

[linux@bashcommandnotfound.cn ~]$ axel -h
Usage: axel [options] url1 [url2] [url...]

--max-speed=x		-s x	Specify maximum speed (bytes per second)
--num-connections=x	-n x	Specify maximum number of connections
--output=f		-o f	Specify local output file
--search[=x]		-S [x]	Search for mirrors and download from x servers
--header=x		-H x	Add header string
--user-agent=x		-U x	Set user agent
--no-proxy		-N	Just don't use any proxy server
--quiet			-q	Leave stdout alone
--verbose		-v	More status information
--alternate		-a	Alternate progress indicator
--help			-h	This information
--version		-V	Version information

Visit https://github.com/axel-download-accelerator/axel/issues to report bugs

如果你想查看axel的版本信息,即axel的版本号和版权声明,你可以使用-v或--version选项,如:

[linux@bashcommandnotfound.cn ~]$ axel -V
Axel version 2.17.10 (Linux)
Please, do not bother the authors with bug reports
unless using the latest version available at
https://github.com/axel-download-accelerator/axel/releases
or with the latest code available at
https://github.com/axel-download-accelerator/axel

Linux axel命令的注意事项

在使用axel命令时,有一些注意事项需要了解,如下:

  • axel命令不支持HTTPS证书验证,如果你下载的文件是通过HTTPS协议提供的,你可能会收到一个警告信息,如:
[linux@bashcommandnotfound.cn ~]$ axel https://www.gnu.org/software/emacs/manual/pdf/emacs.pdf
Initializing download: https://www.gnu.org/software/emacs/manual/pdf/emacs.pdf
SSL: certificate subject `CN=*.gnu.org,O=Free Software Foundation\\, Inc.,L=Boston,ST=Massachusetts,C=US', issuer `CN=R3,O=Let\'s Encrypt,C=US'
WARNING: Certificate verification disabled
File size: 16086356 bytes
Opening output file emacs.pdf
Starting download

Connection 0 finished
Connection 1 finished
Connection 2 finished
Connection 3 finished

Downloaded 15.3 megabytes in 6 seconds. (2550.00 KB/s)

这表示axel没有验证服务器的证书,可能存在安全风险,你可以选择忽略或取消下载。

  • axel命令不支持多个URL指定不同的输出文件名,如果你使用-o或--output选项指定了一个输出文件名,但是有多个URL,那么axel会将所有的URL都下载到同一个文件中,这可能会导致文件损坏或覆盖。
0

评论区