TranslateProject/translated/tech/20170104 Speed up your downloads with Axel command line downloader.md

330 lines
15 KiB
Markdown
Raw Normal View History

2017-01-13 11:00:33 +08:00
使用 Axel 命令行下载器/加速器加速你的下载
2017-01-12 10:42:52 +08:00
============================================================
2017-01-13 11:00:33 +08:00
[Axel][7] 是一个轻量级下载程序,它如其他加速器那样做着同样的事情。它为一个文件打开多个连接,每个连接下载单独的文件片段以更快地完成下载。
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
Axel支持 HTTP】HTTPS、FTP和 FTPS 协议。它也可以使用多个镜像下载单个文件。所以Axel 可以加速下载高达 40大约我个人认为。它非常轻量级因为它没有依赖并且使用非常少的 CPU 和 RAM。
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
Axel 使用一个单线程将所有数据直接下载到目标文件。
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
注意:没有选项可以在单条命令中下载两个文件
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
你还可以尝试其他命令行下载管理器/加速器
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
* [[aria2 - 超快速下载程序] [1]
* [[wget - 标准命令行下载程序] [2]
* [[curl - 命令行下载程序] [3]
* [[Linux 下的最好的 4 个命令行下载管理器/加速器] [4]
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
大多数发行版Debian、Ubuntu、Mint、Fedora、suse、openSUSE、Arch Linux、Manjaro、Mageia等都有 axel 包所以我们可以从发行版官方仓库轻松安装。对于CentOS/RHEL我们需要启用[EPEL Repository][5]。
2017-01-12 10:42:52 +08:00
```
2017-01-13 11:00:33 +08:00
[在 Debian/Ubuntu/LinuxMint 上安装 Axel]
2017-01-12 10:42:52 +08:00
$ sudo apt-get install axel
2017-01-13 11:00:33 +08:00
[在 RHEL/CentOS 上安装 Axel]
2017-01-12 10:42:52 +08:00
$ sudo yum install axel
2017-01-13 11:00:33 +08:00
[在 Fedora 上安装 Axel]
2017-01-12 10:42:52 +08:00
$ sudo dnf install axel
2017-01-13 11:00:33 +08:00
[在 openSUSE 上安装 Axel]
2017-01-12 10:42:52 +08:00
$ sudo zypper install axel
2017-01-13 11:00:33 +08:00
[在 Mageia 上安装 Axel]
2017-01-12 10:42:52 +08:00
$ sudo urpmi axel
2017-01-13 11:00:33 +08:00
[在基于 Arch Linux 的发行版安装 Axel]
2017-01-12 10:42:52 +08:00
$ sudo pacman -S axel
```
2017-01-13 11:00:33 +08:00
#### 1) 下载单个文件
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
以下命令将从给定的 URL 下载文件并存储在当前目录中,而下载文件时,我们可以看到文件的信息(建立的连接数、下载速度、下载进度、完成下载所花费的时间以及连接完成的时间)。
2017-01-12 10:42:52 +08:00
```
# axel https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
Initializing download: https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
File size: 22678208 bytes
Opening output file owncloud-9.0.0.tar.bz2
Starting download
[ 0%] .......... .......... .......... .......... .......... [ 146.7KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 267.0KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 373.9KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 406.9KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 487.5KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 572.6KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 650.7KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 649.3KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 718.1KB/s]
[ 2%] .......... .......... .......... .......... .......... [ 769.3KB/s]
[ 2%] .......... .......... .......... .......... .......... [ 838.7KB/s]
[ 2%] .......... .......... .......... .......... .......... [ 866.0KB/s]
Connection 0 finished
.
.
[ 99%] .......... .......... .......... .......... .......... [5721.0KB/s]
Connection 2 finished
[ 99%] .......... .......... .......... .......... .......... [5733.4KB/s]
Connection 1 finished
[ 99%] .......... .......... .......... .......... .......... [5745.4KB/s]
[100%] .......... .......... .......... .......... ......
Downloaded 21.6 megabytes in 3 seconds. (5755.94 KB/s)
```
2017-01-13 11:00:33 +08:00
#### 2) 用不同的名称保存文件
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
你可以通过添加 -o小写选项和文件名来启动下载并使用其他名称来保存文件。这里我们使用 owncloud.tar.bz2 作为保存文件名。
2017-01-12 10:42:52 +08:00
```
# axel -o cloud.tar.bz2 https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
Initializing download: https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
File size: 22678208 bytes
Opening output file cloud.tar.bz2
Starting download
[ 0%] .......... .......... .......... .......... .......... [ 143.0KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 264.1KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 309.8KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 406.3KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 495.4KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 586.3KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 673.1KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 647.1KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 721.1KB/s]
[ 2%] .......... .......... .......... .......... .......... [ 781.3KB/s]
Connection 2 finished
.
.
Connection 0 finished
[ 98%] .......... .......... .......... .......... .......... [6221.9KB/s]
[ 98%] .......... .......... .....
Connection 1 finished
,,,,,,,,,, ,,,,,,,,,, ,,,,,..... .......... .......... [6145.6KB/s]
[ 99%] .......... .......... .......... .......... .......... [6159.2KB/s]
[ 99%] .......... .......... .......... .......... .......... [6172.0KB/s]
[ 99%] .......... .......... .......... .......... .......... [5977.9KB/s]
[ 99%] .......... .......... .......... .......... .......... [5989.6KB/s]
[100%] .......... .......... .......... .......... ......
Downloaded 21.6 megabytes in 3 seconds. (6001.05 KB/s)
```
2017-01-13 11:00:33 +08:00
#### 3) 限制下载速度
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
默认上 axel 以字节/秒为单位设置下载文件的最大速度。当我们的网络连接速度较慢时,我们可以使用此选项。只需添加 `-s` 选项,后面跟字节值。这里我们要下载一个限速为 `512 KB/s` 的文件。
2017-01-12 10:42:52 +08:00
```
# axel -s 512000 https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
Initializing download: https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
File size: 22678208 bytes
Opening output file owncloud-9.0.0.tar.bz2
Starting download
[ 0%] .......... .......... .......... .......... .......... [ 141.5KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 266.1KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 308.0KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 405.9KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 496.7KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 526.4KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 507.0KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 505.6KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 504.8KB/s]
[ 2%] .......... .......... .......... .......... .......... [ 503.9KB/s]
[ 2%] .......... .......... .......... .......... .......... [ 503.4KB/s]
.
.
[ 99%] .......... .......... .......... .......... .......... [ 497.0KB/s]
[ 99%] .......... .......... .......... .......... .......... [ 496.9KB/s]
[100%] .......... ..
Connection 0 finished
,,,,,,,,,, ,,.....
Connection 1 finished
Connection 3 finished
,,,,,,,,,, ,,,,,,,... .......... .......... ......
Downloaded 21.6 megabytes in 44 seconds. (494.54 KB/s)
```
2017-01-13 11:00:33 +08:00
#### 4) 限制连接数
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
axel 默认建立 4 个连接以从不同的镜像获取文件。此外,我们可以通过使用 `-n` 选项添加更多的连接,后跟连接数 `8` 来提高下载速度。我们为了更安全新添加了八个连接,但不幸的是,它花了更多时间来下载文件。
2017-01-12 10:42:52 +08:00
```
# axel -n 10 https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
Initializing download: https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
File size: 22678208 bytes
Opening output file owncloud-9.0.0.tar.bz2
Starting download
[ 0%] .......... .......... .......... .......... .......... [ 140.8KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 265.7KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 305.4KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 402.1KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 496.3KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 522.1KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 567.5KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 640.5KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 710.8KB/s]
[ 2%] .......... .......... .......... .......... .......... [ 780.5KB/s]
.
.
[ 98%] .......... .......... .......... .......... .......... [7544.9KB/s]
[ 98%] .......... .......... .......... .......... .......... [7557.9KB/s]
[ 98%] .......... .......... .......... .......... .......... [7570.4KB/s]
[ 98%] .......... .......... .......... .......... .......... [7495.3KB/s]
[ 99%] .......... .......... .......... .......... ......
Connection 2 finished
,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,.... [7311.6KB/s]
[ 99%] .......... .......... .......... .......... .......... [7318.9KB/s]
[ 99%] .......... .......... .......... .......... ..........
Connection 9 finished
,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, [7331.0KB/s]
[ 99%] .......... .......... .......... ..........
Connection 3 finished
,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, .......... [4300.7KB/s]
[100%] .......... .......... .......... .......... ......
Downloaded 21.6 megabytes in 5 seconds. (4109.41 KB/s)
```
2017-01-13 11:00:33 +08:00
#### 5) 恢复未完成的下载
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
axel 默认具有恢复未完成的下载的行为。Axel 在下载文件时定期更新状态文件(扩展名为 .st。由于某些原因下载中途停止了不用担心只要使用相同的 axel 命令,它将会检查 `file``file.st`,如果找到,它会从停止处恢复下载。
2017-01-12 10:42:52 +08:00
```
# axel https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
Initializing download: https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
File size: 22678208 bytes
Opening output file owncloud-9.0.0.tar.bz2
Starting download
[ 0%] .......... .......... .......... .......... .......... [ 140.8KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 265.7KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 305.4KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 402.1KB/s]
[ 0%] .......... .......... .......... .......... .......... [ 496.3KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 522.1KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 567.5KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 640.5KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 710.8KB/s]
[ 2%] .......... .......... .......... .......... .......... [ 780.5KB/s]
.
.
[ 84%] .......... .......... .......... .......... .......... [7100.7KB/s]
[ 84%] .......... .......... .......... .......... .......... [7104.3KB/s]
[ 84%] .......... .......... .......... .^C
Downloaded 18.3 megabytes in 2 seconds. (7009.79 KB/s)
```
2017-01-13 11:00:33 +08:00
上面的输出清晰地显示了在下载断开时有两个文件 `owncloud-9.0.0.tar.bz2``owncloud-9.0.0.tar.bz2.st`。当重新开始下载时,它会从停止处开始下载。
2017-01-12 10:42:52 +08:00
```
# ls -lh
total 19M
-rw------- 1 root root 22M Dec 27 08:33 owncloud-9.0.0.tar.bz2
-rw------- 1 root root 44 Dec 27 08:33 owncloud-9.0.0.tar.bz2.st
# axel https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
Initializing download: https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
File size: 22678208 bytes
Opening output file owncloud-9.0.0.tar.bz2
State file found: 19180828 bytes downloaded, 3497380 to go.
Starting download
,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,......... .......... [ 66.5KB/s]
[ 84%] .......... .......... .......... .......... .......... [ 186.0KB/s]
[ 85%] .......... .......... .......... .......... .......... [ 241.7KB/s]
[ 85%] .......... .......... .......... .......... .......... [ 335.6KB/s]
[ 85%] .......... .......... .......... .......... .......... [ 351.5KB/s]
[ 85%] .......... .......... .......... .......... .......... [ 427.1KB/s]
[ 85%] .......... .......... .......... .......... .......... [ 427.4KB/s]
[ 86%] .......... .......... .......... .......... .......... [ 491.5KB/s]
.
.
[ 98%] ...
Connection 0 finished
,,,....... .......... .......... .......... .......... [2106.6KB/s]
[ 99%] .......... .......... .......... .......... .......... [2140.5KB/s]
[ 99%] .......... .......... .......... .......... .......... [2172.4KB/s]
[ 99%] .......... .......... .......... .......... .......... [2203.2KB/s]
[ 99%] .......... .......... .......... .......... .......... [2236.2KB/s]
[100%] .......... .......... .......... .......... ......
Downloaded 3415.4 kilobytes in 1 second. (2264.93 KB/s)
```
2017-01-13 11:00:33 +08:00
#### 6) 不显示文件下载进度
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
如果你不想要看到文件的下载进度,只要在 axel 命令中加入 `-q` 选项。
2017-01-12 10:42:52 +08:00
```
# axel -q https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
```
2017-01-13 11:00:33 +08:00
#### 7) 替换进度条
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
如果你不喜欢默认的进度条,你可以使用 -a 选项来替换进度条。
2017-01-12 10:42:52 +08:00
```
# axel -a https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
Initializing download: https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
File size: 22678208 bytes
Opening output file owncloud-9.0.0.tar.bz2
Starting download
[ 66%] [......0 ...1 ..........2 ...........3] [ 5.8MB/s] [00:01]^C
Downloaded 14.3 megabytes in 2 seconds. (5916.11 KB/s)
```
2017-01-13 11:00:33 +08:00
我们已经了中断上面的下载,以便在下载文件时能清楚地显示替代进度条状态。一旦文件成功下载后,你可以看到相同的输出,如下所示。
2017-01-12 10:42:52 +08:00
```
# axel -a https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
File size: 22678208 bytes
Opening output file owncloud-9.0.0.tar.bz2
Starting download
Connection 2 finished ]
Connection 1 finished ]
Connection 3 finished ]
Connection 0 finished ]
Downloaded 21.6 megabytes in 4 seconds. (5062.32 KB/s)
```
2017-01-13 11:00:33 +08:00
#### 8) 阅读更多关于 axel
2017-01-12 10:42:52 +08:00
2017-01-13 11:00:33 +08:00
如果你想要了解更多关于 axel 的内容,只需要进入它的手册。
2017-01-12 10:42:52 +08:00
```
# man axel
2017-01-13 11:00:33 +08:00
或者
2017-01-12 10:42:52 +08:00
# axel --help
```
2017-01-13 11:00:33 +08:00
享受吧。。。)
2017-01-12 10:42:52 +08:00
--------------------------------------------------------------------------------
via: http://www.2daygeek.com/axel-command-line-downloader-accelerator-for-linux/
作者:[ MAGESH MARUTHAMUTHU][a]
2017-01-13 11:00:33 +08:00
译者:[geekpi](https://github.com/geekpi)
2017-01-15 17:58:43 +08:00
校对:[jasminepeng](https://github.com/jasminepeng)
2017-01-12 10:42:52 +08:00
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.2daygeek.com/author/magesh/
[1]:http://www.2daygeek.com/aria2-command-line-download-utility-tool/
[2]:http://www.2daygeek.com/wget-command-line-download-utility-tool/
[3]:http://www.2daygeek.com/aria2-command-line-download-utility-tool/
[4]:http://www.2daygeek.com/best-4-command-line-download-managers-accelerators-for-linux/
[5]:http://www.2daygeek.com/install-enable-epel-repository-on-rhel-centos-scientific-linux-oracle-linux/
[6]:http://www.2daygeek.com/author/magesh/
[7]:https://axel.alioth.debian.org/