Linux命令學(xué)習(xí)神器!命令看不懂直接給你解釋?zhuān)?/h1>
大家都知道,Linux 系統(tǒng)有非常多的命令,而且每個(gè)命令又有非常多的用法,想要全部記住所有命令的所有用法,恐怕是一件不可能完成的任務(wù)。
一般情況下,我們學(xué)習(xí)一個(gè)命令時(shí),要么直接百度去搜索它的用法,要么就直接用 man 命令去查看守冗長(zhǎng)的幫助手冊(cè)。這兩個(gè)都可以實(shí)現(xiàn)我們的目標(biāo),但有沒(méi)有更簡(jiǎn)便的方式呢?
答案是必須有的!今天給大家推薦一款有趣而實(shí)用學(xué)習(xí)神器 — kmdr,讓你解鎖 Linux 學(xué)習(xí)新姿勢(shì)。
kmdr 工具最大的亮點(diǎn)就是,如果有一個(gè)長(zhǎng)串命令你看不懂它的用法及意義,它將直接分模塊給你詳細(xì)解釋?zhuān)∵@個(gè)功能真的是非常實(shí)用,因?yàn)槲覀冊(cè)诰W(wǎng)上或書(shū)上難免會(huì)看到各種各樣的命令,如果你看不懂,那將永遠(yuǎn)留下疑惑。而這個(gè)工具就像老師一樣,按模塊一個(gè)個(gè)告訴你命令各個(gè)部分的用法及意義,讓你一目了然!
kmdr 收納了非常多的 CLI 命令解釋?zhuān)绯R?jiàn)的 ansible, conda, docker, git, go, kubectl, mongo, mysql, npm, ruby gems, vagrant 等等,不僅如此,那些 bash 內(nèi)置命令 它都能為你解釋?zhuān)浅=o力!
不管你是哪個(gè)領(lǐng)域的程序員,kmdr 都能最大限度地為你提供 CLI 命令學(xué)習(xí)幫助。
- Bash Shell 命令(如 echo,export,cd)
- 容器(如 Docker,kubectl)
- 版本控制(如 Git)
- 數(shù)據(jù)庫(kù)服務(wù)器和客戶(hù)端(如 mysql,mongod)
- 部署/云(如 now cloud)
- 文件和存檔工具(如 zip,tar)
- 媒體(如 ffmpeg,youtube-dl)
- 網(wǎng)絡(luò)/通訊(如 netstat,nmap,curl)
- 包管理器(如 dpkg,pip)
- 編程語(yǔ)言/運(yùn)行時(shí)環(huán)境/編譯器(如 go,python,node,gcc)
- 系統(tǒng)管理 /監(jiān)控(如 crontab,top)
- 文字處理(如 awk,sed)
- 文本編輯器(如 nano,vim)
- 其他(如 openssl,bash,bash64)
這個(gè)鏈接里可以查看完整的支持列表:https://github.com/ediardo/kmdr-cli#supported-programs)
安裝 Kmdr CLI
kmdr 是用 Nodejs 編寫(xiě)的免費(fèi)開(kāi)源工具,需要 Nodejs 版本 8.x 或更高版本才能運(yùn)行,需要大家先準(zhǔn)備好運(yùn)行環(huán)境。
安裝好 Nodejs 之后,使用 Npm 軟件包管理器安裝 kmdr:
- $ npm install kmdr@latest --global
不想安裝 Nodejs 這么麻煩?沒(méi)關(guān)系,這里有一個(gè)網(wǎng)站可以讓你在 web 瀏覽器直接使用 kmdr ↓↓
使用 Kmdr 在終端中顯示 CLI 命令說(shuō)明
下面我們通過(guò)一條復(fù)雜點(diǎn)的命令作為例子,來(lái)看看 kmdr 究竟有多強(qiáng)!
- $ history | awk '{print $2}' | sort | uniq -c | sort -nr | head -5
首先,運(yùn)行下面的命令,讓 kmdr 進(jìn)入解釋狀態(tài):
- $ kmdr explain
接著,輸入我們上面的示例命令,然后按 ENTER 鍵:
- ? Enter your command: history | awk '{print $2}' | sort | uniq -c | sort -nr | head -5
- history
- With no options, display the command history list with line numbers.
- |
- A pipe serves the sdout of the previous command as input (stdin) to the next one
- awk
- pattern scanning and processing language
- {print $2}
- An argument
- |
- A pipe serves the sdout of the previous command as input (stdin) to the next one
- sort
- Sort lines of text files
- |
- A pipe serves the sdout of the previous command as input (stdin) to the next one
- uniq
- Report or omit repeated lines
- -c, --count
- Prefix lines by the number of occurrences
- |
- A pipe serves the sdout of the previous command as input (stdin) to the next one
- sort
- Sort lines of text files
- -n, --numeric-sort
- Compare according to string numerical value
- -r, --reverse
- Reverse the result of comparisons
- |
- A pipe serves the sdout of the previous command as input (stdin) to the next one
- head
- Output the first part of files
- -5
- An argument
- 🤖 Did we help you better understand this command? (Use arrow keys)
- ❯ Skip & Exit
- ──────────────
- Yes
- No
可以看到 kmdr 這個(gè)命令的強(qiáng)大之處,它將那條復(fù)雜命令中每個(gè)部分的解釋都給你列出來(lái)了,讓你一目了然,一看就懂!
如果一個(gè)長(zhǎng)串復(fù)雜命令里面包含了多個(gè)子命令,kmdr 也可以一個(gè)個(gè)為你解釋。
還可以解釋具有分組選項(xiàng)的命令。
- $ kmdr explain
- ? Enter your command: rsync -avz --exclude 'liangxu' dir1/ dir2/
- rsync
- A fast, versatile, remote (and local) file-copying tool
- -a, --archive
- This is equivalent to -rlptgoD.
- -v, --verbose
- This option increases the amount of information you are given during the transfer.
- -z, --compress
- With this option, rsync compresses the file data as it is sent to the destination machine,which reduces the amount of data being transmitted -- something that is useful over a slow connection.
- --exclude
- This option is a simplified form of the --filter option that defaults to an exclude rule anddoes not allow the full rule-parsing syntax of normal filter rules.
- liangxu
- An argument
- dir1/
- An argument
- dir2/
- An argument
- 🤖 Did we help you better understand this command? (Use arrow keys)
- ❯ Skip & Exit
- ──────────────
- Yes
- No
總結(jié)
個(gè)人認(rèn)為,查看 CLI 命令的幫助文檔,一來(lái)其內(nèi)容多而長(zhǎng),二來(lái)仔細(xì)去找會(huì)浪費(fèi)時(shí)間和精力。而 kmdr 只要你輸入你不懂的命令,直接就給你整明白,難道它不香嗎?大家快點(diǎn)去試試吧。