賈浩楠 發自 凹非寺

量子位 報道 | 公衆號 QbitAI

無論你是Linux萌新用戶還是老司機,使用命令行總會遇到不懂的問題。

遇到問題要麼去論壇詢問、谷歌搜索,要麼查自帶命令手冊(RTFM),過程耗時,結果也不直觀。

一位印度軟件工程師針對這一難題,開發了一個便捷的命令行操作指南Q&A工具 howdoi

直接在終端輸入「how do i +你要問的問題」,這裏的問題不再是複雜的命令選項,而是普通的自然語言,和你去谷歌搜索沒什麼兩樣。

然後howdoi馬上就能返回詳細操作教程, 實現了用日常對話的形式來查詢Linux交互命令

這麼 好用的工具安裝起來也不復雜。

安裝步驟

安裝howdoi只要兩步,還需要PHP 5.0以上版本。

運行下方命令即可完成安裝:


$ mkdir -p ~/bin && wget https://raw.githubusercontent.com/san-kumar/howdoi/master/howdoi -O ~/bin/howdoi && chmod +x ~/bin/howdoi

$ sudo ln -s ~/bin/howdoi /usr/local/bin/howdoi

在使用時,有幾個實用的命令字符:

howdoi [-n -v -h] — question

其中,-n 代表返回的解答數量(默認爲1),-v表示返回完整解答(默認情況只返回相關代碼),-h爲顯示此問題的幫助信息。

操作實例

快速查詢教程

輸入問題「如何解壓bz2文件?」:

$ howdoi extract a bz2 file

返回結果:


-j, —bzip2

filter the archive through bzip2

tar -xvjf enginsxt.tar.bz2

Source: https://askubuntu.com/questions/707861/how-to-extract-tar-bz2

howdoi不僅給出了命令的使用方法,還給出了這個問題的來源網址。

詳細教程查詢:

輸入問題「如何把一個程序添加到cron中?」:

$ howdoi -v add a program to cron

返回結果:


Put a shell script in one of these folders: /etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly or /etc/cron.weekly.

If these are not enough for you, you can add more specific tasks e.g. twice a month or every 5 minutes. Go to the terminal and type:

crontab -e

…snip

Source: https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job

對於這樣一個有延伸拓展的問題,返回結果除了有基本的操作指導,還有關於這個問題進一步的建議。

返回多個結果

輸入問題「如何鏈接屏幕?」,要求2個返回結果:

$ howdoi -n 2 attach to a screen

返回:


screen

screen -S myprogramrunningunderscreen

screen -ls

There are screens on:

4964.myprogramrunningunderscreen (05/31/2013 09:42:29 PM) (Detached)

4874.pts-1.creeper (05/31/2013 09:39:12 PM) (Detached)

Source: https://askubuntu.com/questions/302662/reattaching-to-an-existing-screen-session


screen -d -r

Source: https://askubuntu.com/questions/302662/reattaching-to-an-existing-screen-session

這個例子中,在命令中要求返回2個結果,系統返回也給出了兩種連接不同屏幕的方法。

其他功能

還可以查詢如何更新PHP:


$ howdoi upgrade to latest php

sudo apt-get upgrade

sudo apt-get dist-upgrade

sudo apt-add-repository ppa:ondrej/php

sudo apt-add-repository ppa:ondrej/php5-oldstable

sudo apt-add-repository ppa:ondrej/php5

sudo apt-add-repository ppa:ondrej/php5-5.6

sudo apt-get update

sudo apt-get install php5.5

sudo apt-get install php5.6

sudo apt-get install php7.0

do-release-upgrade

Source: https://askubuntu.com/questions/565784/how-do-i-upgrade-php-version-to-the-latest-stable-released-version

howdoi工具調用的解答庫來源於askbuntu.com論壇上的提問,論壇上已有的問題解答都可以通過本工具實現 對話式查詢

5月19日,這個項目剛剛在Github上開源。

顯卡驅動、硬件支持、圖形平臺穩定、用戶體驗、軟件支持、社區協作,這些小問題疊加在一起,成了誰都無法忽視的Linux缺陷,這些痛點也許就是讓新用戶望而生畏的真正原因。

本項目在Hacker news上收穫了網友的盛讚,其中有一位用戶在稱讚之餘,還指出了像Linux這種類Unix系統的通病:用戶友好性差,獲取幫助十分困難。

這位印度小哥San Kumar解決了一個大問題:Linux新手無法高效獲取問題的解決方案 ,而且整個工具只用了100行代碼實現。

同時這位用戶還建議這種實用工具今後應該作爲標準,加入所有類Unix操作系統的衍生版本。

如果這個Linux利器對你有幫助的話,可以直接通過文中的代碼下載,項目原址在下方。

Github項目地址:

https://github.com/san-kumar/howdoi

— 完 —

特惠福利 | 一站式音視頻解決方案

想趕上直播電商、在線教育、小程序直播的風口?騰訊雲音視頻解決方案爲您助力!

騰訊雲推出9.9元產品體驗包,包括雲點播、雲直播、實時音視頻,總有一款適合你。識別二維碼即可體驗:

量子位  QbitAI · 頭條號簽約作者

վ'ᴗ' ի 追蹤AI技術和產品新動態

喜歡就點「在看」吧 !

相關文章