1 前言
linux命令非常多,少用的命令往往易忘记,甚至常用的语法较为复杂的命令也不好记住。当然有些太复杂的命令也不需要死记硬背,我们往往会借助man
命令去查找命令的具有用法。man
功能着实强大,但有的时候显得繁琐累赘;我们只需要关键的使用语法、例子,man
给出了一堆详细信息,影响我们提取关键信息,特别是比较陌生的命令。
acuity@ubuntu:~$ man tar
TAR(1) BSD General Commands Manual TAR(1)
NAME
tar — The GNU version of the tar archiving utility
SYNOPSIS
tar [-] A --catenate --concatenate | c --create | d --diff --compare | --delete | r --append | t --list | --test-label | u --update | x --extract --get [options] [pathname ...]
DESCRIPTION
Tar stores and extracts files from a tape or disk archive.
The first argument to tar should be a function; either one of the letters Acdrtux, or one of the long function names. A function letter need not be prefixed with ``-'', and may be combined with other single-letter
options. A long function name must be prefixed with --. Some options take a parameter; with the single-letter form these must be given as separate arguments. With the long form, they may be given by appending =value to
the option.
FUNCTION LETTERS
Main operation mode:
-A, --catenate, --concatenate
append tar files to an archive
-c, --create
create a new archive
-d, --diff, --compare
find differences between archive and file system
--delete
delete from the archive (not on mag tapes!)
-r, --append
append files to the end of an archive
-t, --list
list the contents of an archive
--test-label
test the archive volume label and exit
总会有一些高效的工具出现,去改变一些东西,比如tldr
工具,一个使用非常方便、高效的linux命令工具查询器,而且还是开源的。
2 tldr
tldr
,作者给出的含义是Too Long; Didn’t Read
,直译即是“太长,不值得一读”,严重怀疑在明嘲暗讽man
。tldr
简化了烦琐的man
的输出帮助信息,只列出关键的语法信息、例子,方便用户使用。
tldr
开源地址:https://github.com/tldr-pages/tldr
3 安装
tldr
安装比较简单,主机联网状态下,可以直接在线安装。x64 ubuntu16 安装步骤如下:
- 第一步, 安装
npm
sudo apt-get install npm -y
为了快速下载,我们先更新一下npm 的包镜像源:
sudo npm config set registry https://registry.npm.taobao.org
接着升级到最新版本的npm:
sudo npm install npm@latest -g
- 第二步,安装
nodejs
sudo apt install nodejs
可能会提示如下错误:
acuity@ubuntu:~$ sudo apt install nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
gyp libjs-inherits libjs-node-uuid libjs-underscore libuv1 libuv1-dev node-abbrev node-ansi node-ansi-color-table node-archy node-async node-block-stream node-combined-stream node-cookie-jar node-delayed-stream node-forever-agent
node-form-data node-fstream node-fstream-ignore node-github-url-from-git node-glob node-graceful-fs node-gyp node-inherits node-ini node-json-stringify-safe node-lockfile node-lru-cache node-mime node-minimatch node-mkdirp
node-mute-stream node-node-uuid node-nopt node-normalize-package-data node-npmlog node-once node-osenv node-qs node-read node-read-package-json node-request node-retry node-rimraf node-semver node-sha node-sigmund node-slide
node-tar node-tunnel-agent node-underscore node-which
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
nodejs-dev nodejs-legacy npm
The following packages will be upgraded:
nodejs
1 upgraded, 0 newly installed, 3 to remove and 89 not upgraded.
Need to get 18.1 MB of archives.
After this operation, 68.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://deb.nodesource.com/node_12.x xenial/main amd64 nodejs amd64 12.20.1-1nodesource1 [18.1 MB]
Err:1 https://deb.nodesource.com/node_12.x xenial/main amd64 nodejs amd64 12.20.1-1nodesource1 Operation too slow. Less than 10 bytes/sec transferred the last 120 seconds
E: Failed to fetch https://deb.nodesource.com/node_12.x/pool/main/n/nodejs/nodejs_12.20.1-1nodesource1_amd64.deb Operation too slow. Less than 10 bytes/sec transferred the last 120 seconds
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
如果出现该错误,说明安装源过于陈旧,根据以下步骤更新安装源:
【1】配置域名解析文件resolv.conf
,增加“nameserver 8.8.8.8”
内容
sudo vim /etc/resolv.conf
【2】更新安装源
sudo apt-get update
更新完成,再执行sudo apt install nodejs
即可成功安装nodejs
。
- 第三步,安装
tldr
sudo npm install -g tldr
- 第四步,使用前建议先更新下
sudo tldr --update
4 使用
执行tldr
会提示使用方法,还有例子,很是人性化。
acuity@ubuntu:~$ tldr
Usage: tldr command [options]
Simplified and community-driven man pages
Options:
-V, --version output the version number
-l, --list List all commands for the chosen platform in the cache
-a, --list-all List all commands in the cache
-1, --single-column List single command per line (use with options -l or -a)
-r, --random Show a random command
-e, --random-example Show a random example
-f, --render [file] Render a specific markdown [file]
-m, --markdown Output in markdown format
-o, --os [type] Override the operating system [linux, osx, sunos]
--linux Override the operating system with Linux
--osx Override the operating system with OSX
--sunos Override the operating system with SunOS
-t, --theme [theme] Color theme (simple, base16, ocean)
-s, --search [keywords] Search pages using keywords
-u, --update Update the local cache
-c, --clear-cache Clear the local cache
-h, --help display help for command
Examples:
$ tldr tar
$ tldr du --os=linux
$ tldr --search "create symbolic link to file"
$ tldr --list
$ tldr --list-all
$ tldr --random
$ tldr --random-example
To control the cache:
$ tldr --update
$ tldr --clear-cache
To render a local file (for testing):
$ tldr --render /path/to/file.md
查询tar
命令的使用方法,与前面的man
的查询结果相比,tldr
的结果显得通俗、精炼,方便用户抓住关键信息。
acuity@ubuntu:~$ tldr tar
✔ Page not found. Updating cache...
✔ Creating index...
tar
Archiving utility.
Often combined with a compression method, such as gzip or bzip.
More information: https://www.gnu.org/software/tar.
- [c]reate an archive from [f]iles:
tar cf target.tar file1 file2 file3
- [c]reate a g[z]ipped archive from [f]iles:
tar czf target.tar.gz file1 file2 file3
- [c]reate a g[z]ipped archive from a directory using relative paths:
tar czf target.tar.gz --directory=path/to/directory .
- E[x]tract a (compressed) archive [f]ile into the current directory:
tar xf source.tar[.gz|.bz2|.xz]
- E[x]tract a (compressed) archive [f]ile into the target directory:
tar xf source.tar[.gz|.bz2|.xz] --directory=directory
- [c]reate a compressed archive from [f]iles, using [a]rchive suffix to determine the compression program:
tar caf target.tar.xz file1 file2 file3
- Lis[t] the contents of a tar [f]ile [v]erbosely:
tar tvf source.tar
- E[x]tract [f]iles matching a pattern:
tar xf source.tar --wildcards "*.html"