天天看點

Betty:和你的Linux說說話Betty:和你的Linux說說話

betty 是一個将類英語短語翻譯成linux指令的開源工具。這個項目的主要目的是讓大家可以通過輸入自然語言來使用強大的linux系統。讓我們來看一下它是怎麼工作的。

Betty:和你的Linux說說話Betty:和你的Linux說說話

<a target="_blank"></a>

betty的安裝非常簡單直接。首先确認你已經安裝了下面這些依賴包[lctt譯注,需要安裝至少ruby1.9以上版本]。

sudo apt-get install git curl ruby

yum install git curl ruby

現在用git工具把betty庫clone到你自定義的任何路徑。這裡我克隆到我的home目錄,例如 /home/sk/.

git clone https://github.com/pickhardt/betty

添加betty的别名到你的bashrc配置檔案。

sudo nano ~/.bashrc

将下列行添加到檔案的末尾:

alias betty="/home/sk/betty/main.rb"

確定你已經正确地設定好了betty的路徑。

好了,現在是時候和betty好好地玩耍了。

你應該在英語短語之前加上單詞“betty” [lctt譯注,你自然可以用你的小甜心的名字來替換這個不是知道是誰的betty :&gt;]。你也許已經知道,如果我們想知道在系統中我們的使用者名,應該運作下面的指令:

whoami

輸出是這樣的:

sk

如你所見,我目前登入的使用者名是 sk. 現在我也可以通過下面的betty指令擷取相同的結果。

betty whats my username

betty: running whoami

真的好酷,是不是?betty了解我輸入的“whats my username”短語,然後運作“whoami”指令,最後輸出結果。

讓我們也來看其他指令。

如果你的輸入不夠準确,betty也能以多種方式回應你。例如,我們運作下面的指令:

betty whats my name

betty不确定她應該查找系統使用者名還是使用者全名。這種情況下,她會詢問你多個問題來找到準确的結果。如你下面所見,betty問我想要運作哪一條指令(whoami 還是 finger $(whoami) | sed 's/.://;q')[lctt譯注,需要你的系統已經安裝finger]。我隻想知道我的使用者名,是以我選擇數字1。

betty: okay, i have multiple ways to respond.

betty: enter the number of the command you want me to run, or n (no) if you don't want me to run any.

[1] whoami

gets your system username.

[2] finger $(whoami) | sed 's/.*: *//;q'

gets your full name.

1

如果你想要壓縮一個檔案或者檔案夾,用下面的指令。例如,我想壓縮我home目錄下的“test”檔案夾。

betty compress test/ test.tar.gz

betty: running tar -czvf test.tar.gz test/

test/

test/home/

test/home/sk/

test/home/sk/test/

test/home/sk/test/sample

類似的,我們可以用下面的指令來解壓縮一個歸檔檔案。

betty uncompress test.tar.gz

betty: running mkdir test &amp;&amp; tar -zxvf test.tar.gz -c test

betty工具有一些指令格式。如果你輸入“what is my user name”而不是“whats my username”,它是不能識别的。是以,你隻能輸入betty支援的英語短語。

下面給出一個betty支援的完整的指令行清單。

count:

betty how many words are in this directory

betty how many characters are in myfile.py

betty count lines in this folder

(note that there's many ways to say more or less the same thing.)

config:

betty change your name to joe

betty speak to me

betty stop speaking to me

datetime:

betty what time is it

betty what is todays date

betty what month is it

betty whats today

find:

betty find me all files that contain california

internet:

betty download http://www.mysite.com/something.tar.gz to something.tar.gz

betty uncompress something.tar.gz

betty unarchive something.tar.gz to somedir

(you can use unzip, unarchive, untar, uncompress, and expand interchangeably.)

betty compress /path/to/dir

itunes:

betty mute itunes

betty unmute itunes

betty pause the music

betty resume itunes

betty stop my music

betty next song

betty prev track

betty what song is playing

(note that the words song, track, music, etc. are interchangeable)

fun:

betty go crazy

betty whats the meaning of life

...and more that are left for you to discover!

map:

betty show me a map of mountain view

meta:

betty what version are you (or just betty version)

betty whats your github again

permissions:

betty give me permission to this directory

betty give anotheruser ownership of myfile.txt

process:

betty show me all processes by root containing grep

betty show me all my processes containing netbio

sizes:

betty show size for myfile.txt

spotify:

betty play spotify

betty pause spotify

betty next spotify

betty previous spotify

user:

betty whats my real name

betty whats my ip address

betty who else is logged in

betty whats my version of ruby

web queries:

betty turn web on

betty please tell me what is the weather like in london

對linux初級使用者來說,betty似乎是一個非常nice的工具。希望這個工具對你也會非常有用。

cheers!

原文釋出時間:2014-07-23

本文來自雲栖合作夥伴“linux中國”

繼續閱讀