Linux 的日常 tools

Linux基础命令里的就不再赘述了。

Table of Contents

  1. 一、下载(命令行工具,只给出常用的命令说明)
    1. wget/cURL(一般系统自带)
    2. aria2/axel多线程下载
      1. 1. aria2
      2. 2. axel
    3. youtube-dl
      1. 下载时的常用选项
      2. 使用示例
      3. 直接输出流到vlc
    4. you-get
  2. 二、音频/视频播放
    1. 视频:VLC and MPV
    2. 音频:aplay、arecord
  3. 三、科学的上网
  4. 四、文档处理
  5. 五、云
  6. 五、其他实用
  7. 画外
  8. 参考

一、下载(命令行工具,只给出常用的命令说明)

wget/cURL(一般系统自带)

  • httpie:wget 和 curl 的替代品,功能更强大!!!
  • wget: 轻量快速的下载工具
    • 下载:wget [-O filename] [-c] url
    • O 选项:给下载的文件指定文件名。(不加这个,会使用默认文件名)
    • c 选项:断点续传
  • cURL: 如果 wget 满足不了你的需求,就用 curl
    • 下载:curl [-o filename] url
    • o 选项:和 wget 的 -O 一样,是指定文件名。不过注意是小写。

aria2/axel多线程下载

wget/curl是单线程的,因此在下载大文件时,可能就显得不太合适了。因此出现了 aria2/axel

1. aria2: 神器

aria2 支持 HTTP(S)/FTP/SFTP/BitTorrent 的下载。
同时也是百度网盘下载神器,配合 baidu exporter 简直完美。
基础命令示例:

#download through http/ftp
aria2c download_url

#download through BitTorrent Magnet URI
aria2c "magnet:?xt=urn:btih:248D0A1CD08284299DE78D5C1ED359BB46717D8C&dn=aria2"

#download through a local torrent file
aria2c --max-upload-limit=200K file.torrent

#The -x option specified the number of allowed connections, it should between 1 and 16.
aria2c -x16 "http://host/file.zip"

#-i, --input-file=<FILE> 指定从 files.txt 读取 url 下载
#-j,--max-concurrent-downloads=<N> 指定并行下载数.
aria2c -ifiles.txt -j3

通用的选项可以写入默认配置文件,文件地址是$HOME/.aria2/aria2.conf,也可通过--conf-path=<PATH>手动指定。配置内容可参考 Aria2 配置说明

2. axel

实测 axel 远没有 aria2 快

aria2 下载单文件最多只能开16线程,对付百度云这样限速严重的网站,可能不怎么好用。
而 axel 没这个限制,在需要开更多线程的时候,你就需要使用 axel 了。不过 axel 不支持 torrent,所以 BT下载还是得用 aria2。
使用示例:

-n, --num-connections=x   # 开x线程
-o, --output=filename        # 指定文件名
-H, --header=x                 # 设定请求头
-U, --user-agent=x           # 设定请求头的代理字段

# 开 20 线程下载
axel -n 20 down_url

基本上了解这些就够了,可以看到 axel 比 aria2 简单很多。

youtube-dl

可以说是最火的视频/音乐下载工具了,支持 Youtube、Bilibili、优酷、爱奇艺、网易云音乐、QQ音乐等几乎所有你用得到的网站。(不过国内网站的支持,可能没 you-get及时)
使用正则匹配网站URL,你只需要给出 视频/playlist/channel 的观看用URL,它就从中解析出下载地址,并将视频下载下来。
安装:pip3 install youtube-dl
更新:pip3 install --upgrade youtube-dl

youtube-dl 的的配置文件位于~/.config/youtube-dl/config,可以把常用的配置写入该文件。以下是我的配置:

# Lines starting with # are comments

# default format is:[ -f bestvideo+bestaudio/best], we make it not better than 1080p
-f bestvideo[height<=?1080]+bestaudio/best

# download all subs
--all-subs

# don't overwrite files
 --no-overwrites 

# Use socks5 proxy, so if you want to download without proxy, you whould use `--ignore-config`
--proxy  socks5://127.0.0.1:1080/

# Save all files under Movies directory in your home directory, with it's name: title.extension.
-o ~/Videos/%(title)s-%(id)s.%(ext)s

# 调用外部下载器下载,(aria2/axel)也许能提升下载速度
# --external-downloader aria2
# 设置外部下载器 (aria2) 的参数,可省略。
# --external-downloader-args -x 16

下载时的常用选项

-F, --list-formats               List all available formats of requested videos
-f, --format FORMAT              Video format code, see the "FORMAT
                                 SELECTION" for all the info

-o, --output TEMPLATE            Output filename template, see the "OUTPUT

--write-sub                      Write subtitle file
--write-auto-sub                 Write automatically generated subtitle file
                                 (YouTube only)
--all-subs                       Download all the available subtitles of the
                                 video
--embed-subs                     Embed subtitles in the video (only for mp4,
                                 webm and mkv videos)
--list-subs                      List all available subtitles for the video


-w, --no-overwrites              Do not overwrite files
-c, --continue                   Force resume of partially downloaded files.
                                 By default, youtube-dl will resume
                                 downloads if possible.

-a, --batch-file FILE            File containing URLs to download ('-' for
                                 stdin), one URL per line. Lines starting
                                 with '#', ';' or ']' are considered as
                                 comments and ignored.

--ignore-config                  just as its name

使用示例

# download a video
youtube-dl -o - "https://www.youtube.com/watch?v=BaW_jenozKcj"

# Download YouTube playlist videos in separate directory indexed by video order in a playlist
    youtube-dl -o '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re

# Download all playlists of YouTube channel/user keeping each playlist in separate directory:
    youtube-dl -o '%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/user/TheLinuxFoundation/playlists

直接输出流到vlc

使用-o - 选项,将流直接输出到 stdio,再用管道重定向到 vlc.

youtube-dl -o - "https://www.youtube.com/watch?v=BaW_jenozKcj" | vlc -

you-get

这是另一个比较火的视频/音乐下载工具。(当然,文档/图片等也是可以下的,不过一般直接用wget就行了)
一般来说国外的网站如 Youtube 直接用 youtube-dl 就行了,而 you-get 对国内网站的支持好像是要比 youtube-dl 好,可以考虑用它。
安装:sudo pip3 install you-get
更新:sudo pip3 install --upgrade you-get

you-get 会自动合并同一个视频的流文件,只要你安装了 ffmpeg。

-i, --info        to see all available quality and formats
-o, --output-dir
-O, --output-filename
-x, --http-proxy HOST:PORT     set a http proxy
-s, --socks-proxy HOST:PORT     set a socks5 proxy.
-p, --player         output stream instantly to a player.
-l, --playlist  下载整个列表

example:
    you-get 'https://www.youtube.com/watch?v=jNQXAC9IVRw'             # just download it
    you-get -i 'https://www.youtube.com/watch?v=jNQXAC9IVRw'      # see the info, don't download it
    you-get -o ~/Videos -O zoo.webm 'https://www.youtube.com/watch?v=jNQXAC9IVRw'  # set output path
    you-get -s 127.0.0.1:1080 'https://www.youtube.com/watch?v=jNQXAC9IVRw'      # set http-proxy
    you-get -p vlc 'https://www.youtube.com/watch?v=jNQXAC9IVRw'     # player the video with vlc immediately.

二、音频/视频播放

视频:VLC and MPV

VLC 和 MPV 的 UI 和 性能 都挺不错的,可以尝试一下,看看中意哪个。我个人的感觉是,vlc 功能可能更全一点,但是有点太重,而且初始界面不喜欢。。mpv对我而言就刚刚好。
顺便这两个都有CLI(命令行接口)

音频:aplay、arecord

这些命令来源于 ALSA(Advanced Linux Sound Architecture),该模块是 Linux kernel 的一部分。

arecord -d 5 test-mic.wav
aplay test-mic.wav  #只支持wav

对非 wav 音频,请直接用mpv xxx.mp3vlc xx.mp3 播放. 个人强烈推荐mpv,它默认在命令行界面下播放。(命令行下也是支持快捷键快进快退的)

三、科学的上网

有名的当然是 shadow-socks 了,它的客户端是 sslocal, 客户端启动后,会在 localhost 的指定端口开始监听请求。
如果你的某软件需要走代理,首先它要支持 socks5 协议,然后它要主动把内容发送到 sslocal 监听的端口。为了满足这两个条件,就需要额外的工具:

  1. switchomega - GFWList: chrome 插件,使用它可实现仅 GFWList FQ这样的功能。
  2. proxychains-ng:对其它需要FQ但是不满足上述两个条件的程序,可使用这个工具作为中间层。

四、文档处理

五、云

  • 云仓库:开源项目用 Github 没说的、私有仓库可能会用 coding.net,它提供5个私人仓库(对我来说,完全够了)。
  • 云硬盘:百度云 Wine 版,或者网页版。
  • 云笔记:OneNote网页版
  • 云文件:坚果云 Linux 版。(之前用 Windows 时用的 OneDrive,大概也是该换换了。)
  • 云配置:mackup,自动搜索系统中的各种配置文件,并在 Dropbox/坚果云 的同步文件夹内建立配置文件的软链。并在其他系统上将配置文件从 同步文件夹 恢复到对应的位置。

五、其他实用

画外

上面的软件,给出的链接基本都是 github 仓库,而且很多都是 Python 写的,一些小工具的源码很值得一读。也可以给 youtube-dl 更新一下 b站 的下载规则之类的。
熟悉了这些 tools 后,好像就很难再回到 Windows 了。。cmd.exe 太弱,powershell 在我的渣机器上冷启动要一分钟。。而且输中文还乱码,这还怎么玩?(更新1803后powershell启动倒是快了不少)

参考

posted @ 2018-05-01 17:49  於清樂  阅读(3507)  评论(0编辑  收藏  举报