Linux的10个经典彩蛋

jopen 10年前

每当你打开的Linux虚拟主机的时候,通常是为了完成工作。但是,一台普通的Linux主机上,有成千上万的开发者开发的软件,你能保证他们都是这么正经的?

Linux的软件有加一些有趣的彩蛋的传统。本文主要是介绍一些有趣的命令和选项,让你的生活更多彩一些。这些并非全是彩蛋,不过我相信你多少会喜欢它们的。

文本编辑器

vim和Douglas Adams

熟悉Douglas Adams(也就是The Hitchhiker's Guide to the Galaxy一书的作者)的人,vim编辑器有个帮忙选项会让你赞不绝口。

如果你还没装vim。在Ubuntu/Debian,你可以这样:

sudo apt-get install vim 

在CentOS/Fedora里,可以:

sudo yum install vim 

在命令行打开vim:

vim  

输入以下命令打开vim的一个特殊的帮助菜单:

:help 42    
What is the meaning of life, the universe and everything?  *42* Douglas Adams, the only person who knew what this question really was about is now dead, unfortunately.  So now you might wonder what the meaning of death is 

想退出vim的话,敲两遍这个:

:q :q 

Emacs游戏

从未败绩,除了厨房水槽外包罗万象无所不有的著名文本编辑器, Emacs,它里面包含的游戏多的让你乍舌,直接在编辑器里就能玩。 首先,你得先装一下Emacs,在Ubuntu/Debian,你可以这样:

sudo apt-get install emacs 

在CentOS/Fedora里,可以:

sudo yum install emacs 

看下这个目录你会发现有很多的游戏:

cd /usr/share/emacs/*/lisp/play ls 
5x5.elc       decipher.elc    gametree.elc   meese.elc      spook.elc animate.elc   dissociate.elc  gomoku.elc     morse.elc      studly.elc blackbox.elc  doctor.elc      handwrite.elc  mpuz.elc       tetris.elc bruce.el      dunnet.elc      hanoi.elc      pong.elc       yow.elc bubbles.elc   fortune.elc     landmark.elc   snake.elc      zone.elc cookie1.elc   gamegrid.elc    life.elc       solitaire.elc 

运行它们的话,先打开Emacs:

emacs 

然后同时按下Esc键和x(执行),然后输入你想玩的游戏的名字:

Esc-x pong 

要退出Emacs的话,同时按下ctrl键和x,然后是ctrl+c:

Ctrl-x Ctrl-c 

Apt命令

apt-get的超级牛力

在Ubuntu和Debian上,apt-get这个包管理器很久以来一直都内嵌着一个彩蛋。

如果你输入一个apt-get的帮助命令,你会得到个这样的提示:

apt-get help 
. . . . . .   -c=? Read this configuration file   -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp See the apt-get(8), sources.list(5) and apt.conf(5) manual pages for more information and options.                        This APT has Super Cow Powers. 这个APT有着超级牛力。  

如果看到最后一行的提示说明这个版本的apt是支持这个彩蛋的。再输入一个:

apt-get moo      
         (__)          (oo)    /------\/   / |    ||     *  /\---/\     ~~   ~~  ...."Have you mooed today?"   

Aptitude的呢?

看到apt-get和牛的暧昧关系,用户不禁会想,另一个apt工具aptitude是不是也有这个有趣的彩蛋呢?

我们像之前那样再试一下:

aptitude help  
. . . . . .  -u             Download new package lists on startup.                   (terminal interface only)  -i             Perform an install run on startup.                   (terminal interface only)                   This aptitude does not have Super Cow Powers. 这个aptitude没有超级牛力。  

太令人失望了。再试下别的方式:

aptitude moo  
There are no Easter Eggs in this program(这个程序没有彩蛋).   

太直白了吧。不过坚持很重要。我们再试下有没有更多信息:

aptitude -v moo   
There really are no Easter Eggs in this program.(这个程序真的没有彩蛋)    

再来:

aptitude -vv moo 
Didn't I already tell you that there are no Easter Eggs in this program? 我不是告诉过你这个程序没有彩蛋了吗?  

不过你再不停的加v的话,最终你会看到这个:

aptitude -vvvvv moo 
All right, you win.好吧,你贏了。                                /----\                        -------/      \                       /               \                      /                |    -----------------/                  --------\    ----------------------------------------------  

不过这看着不大像。我们再加一个v:

aptitude -vvvvvv moo 
What is it?  It's an elephant being eaten by a snake, of course. 这是什么?这就是一条蛇吞了一只大象.(看不懂的请自觉搜索小王子) 

这里引用了Antoine de Saint-Exupéry的《小王子》书里的一句话。

常见程序的另类参数

在一些常见的程序中也有些奇怪的参数,这你一定会很好奇。

用sudo来羞辱用户

你可以配置sudo(用来给命令授权的),来羞辱那些输错密码的用户。

想这么做的话,先用个visudo的工具编辑下sudoers文件,这个工具用来编辑sudo配置文件并且进行修改的校验。

sudo visudo 

在文件顶部,加上这么一行:

Defaults insults 

然后保存并且关闭文件。

然后,清空密码的缓存,然后在sudo命令里输入错的密码:

sudo -k sudo ls 
[sudo] password for demo: # 输入一个错的密码 Have you considered trying to match wits with a rutabaga?(你这是在开玩笑么,) [sudo] password for demo: My pet ferret can type better than you!(我的宠物鼬都能敲的比你好!) [sudo] password for demo: Wrong!  You cheating scum! (不对!你个骗子!) 
脚本小子的Nmap输出

Nmap是一款网络检测工具,它可以用来进行系统的安全检查。

在Ubuntu/Dedian上安装一下它:

sudo apt-get install nmap 

在CentOS/Fedora上面这样:

sudo yum install nmap 

Nmap提供了这么一个选项,让它能把数据输出成“脚本小子”的那种格式。

我们先来看下正常的格式是什么样的,用Nmap来检测下它自己的网站:

nmap scanme.nmap.org 
Starting Nmap 5.21 ( http://nmap.org ) at 2013-09-18 17:43 UTC Nmap scan report for scanme.nmap.org (74.207.244.221) Host is up (0.072s latency). Not shown: 998 closed ports PORT   STATE SERVICE 22/tcp open  ssh 80/tcp open  http Nmap done: 1 IP address (1 host up) scanned in 1.40 seconds 

我们来加个选项调整下输出的格式:

$tart|ng NMap 5.21 ( http://Nmap.org ) at 2013-09-18 17:45 UTC Nmap $cAn r3p0rt F0r scanM3.nmaP.oRg (74.207.244.221) Ho$t 1z Up (0.071z laT3ncy). Not sh0wN: 998 cl0$Ed p0rt$ POrT   ST4TE $ERV!C3 22/tcp opEn  Ssh 80/tcP 0p3n  HtTp Nmap d0n3: 1 iP AddrESz (1 h0$t Up) $canNed !n 1.34 secondz 

其实它就是用看起来相近的字符替换了原有的字符,让结果看起来更有“黑客范”一点。

命令行的星球大战

终端里就有两款网络版的命令行的星球大战。

用telnet观看ASCII版的星球大战影片

Simon Jansen, Sten Spans, 和Mike Edwards用ASCII模拟了一个完整的星球大战影片,你可以用telnet来观看它。 首先,如果没有安装的话,下载一下telnet,它是ssh的先驱:

在Ubuntu/Debian上面:

sudo apt-get install telnet 

在CentOS/Fedora上面:

sudo yum install telnet 

然后你只要连上正确的服务器就可以了:

telnet towel.blinkenlights.nl 
                                   /~\                                         R2-D2!                   |oo )                                    Where are you?         #     _\=/_    #                                                       \\  /  _  \  //                                                       \\//|/.\|\\//                                                         \/  \_/  \/                                                              |\ /|                                                                 \_ _/                                                                 | | |                                                                 | | |                                                                 []|[]                                                                 | | |                                 _______________________________/_]_[_\_____________________________ 

如果你不想看了,按下ctrl+]。会有一个提示,然后你输入”close”就行了:

Ctrl-] close 
星球大战版traceroute

还有一份献礼是Ryan Werber送上的,他把网络的节点全都命名成特殊的地址了。

如果你运行traceroute,一个跟踪网络包到远程机器的路径的程序,你会在网络节点名上看到星球大战的介绍。

就敲一下:

traceroute -m 254 -q1 obiwan.scrye.net 

路由信息就会不断产生了。经过几跳后,奇迹发生了:

. . . . . . 15  Episode.IV (206.214.251.1)  77.506 ms 16  A.NEW.HOPE (206.214.251.6)  87.194 ms 17  It.is.a.period.of.civil.war (206.214.251.9)  77.699 ms 18  Rebel.spaceships (206.214.251.14)  78.171 ms 19  striking.from.a.hidden.base (206.214.251.17)  87.624 ms 20  have.won.their.first.victory (206.214.251.22)  86.249 ms 21  against.the.evil.Galactic.Empire (206.214.251.25)  77.505 ms 22  During.the.battle (206.214.251.30)  85.622 ms 23  Rebel.spies.managed (206.214.251.33)  78.121 ms 24  to.steal.secret.plans (206.214.251.38)  77.049 ms . . . . . . 

在第4,5,6幕介绍完后,Ryan开始自娱自乐起来了:

99  Were.no.strangers.to.love (206.214.251.206)  77.472 ms 100  You.know.the.rules.and.so.do.I (206.214.251.209)  78.054 ms 101  A.full.commitments.what.Im.thinking.of (206.214.251.214)  78.512 ms 102  I.just.wanna.tell.you.how.Im.feeling (206.214.251.217)  79.884 ms 103  Gotta.make.you.understand (206.214.251.222)  79.427 ms 104  Never.gonna.give.you.up (206.214.251.225)  77.032 ms 105  Never.gonna.let.you.down (206.214.251.230)  78.909 ms 106  Never.gonna.run.around.and.desert.you (206.214.251.233)  80.286 ms 

纯粹找乐子的程序

还有些程序是你压根儿不需要的,不过有时候可以拿来打发打发时间。

拼写错误学习

如果你想要用ls列出目录下的文件却敲成了sl,那你可能会想安装一下sl这个程序。

在Ubuntu/Debian上面:

sudo apt-get install sl 

在CentOS/Fedora上面:

sudo yum install sl 

现在,如果你不小心敲成了sl,你一定会乐了:

sl 
                          (  ) (@@) ( )  (@)  ()    @@    O     @     O     @                      (@@@)                  (    )               (@@@@)             (   )         ====        ________                ___________     _D _|  |_______/        \__I_I_____===__|_________|      |(_)---  |   H\________/ |   |        =|___ ___|      _________________      /     |  |   H  |  |     |   |         ||_| |_||     _|                \___     |      |  |   H  |__--------------------| [___] |   =|     | ________|___H__/__|_____/[][]~\_______|       |   -|     |/ |   |-----------I_____I [][] []  D   |=======|____|______________________   __/ =| o |=-~~\  /~~\  /~~\  /~~\ ____Y___________|__|________________________    |/-=|___|=O=====O=====O=====O   |_____/~\___/          |_D__D__D_|  |_D__D__D     \_/      \__/  \__/  \__/  \__/      \_/               \_/   \_/    \_/   \  

会有一辆火车呼啸而过。

cowsay和Fortune

如果你想玩点简单脑残的,而apt那些牛又不能满足你,那你可以试试cowsay和fortune。

在Ubuntu/Debian上:

sudo apt-get install fortune cowsay 

在CentOS/Fedora上:

sudo yum install fortune cowsay 

cowsay会用ASCII画一头牛出来,你输入什么,这牛就说什么。

cowsay "hello, I'm a cow 
 __________________ < hello, I'm a cow >  ------------------         \   ^__^          \  (oo)\_______             (__)\       )\/\                 ||----w |                 ||     || 

fortune程序则会说一些语录,运程,笑话或者废话什么的,这些可以拿来传给cowsay程序:

cowsay "hello, I'm a cow 
 ________________________________________ / Q: What looks like a cat, flies like a \ | bat, brays like a donkey, and          | |                                        | \ plays like a monkey? A: Nothing.       /  ----------------------------------------         \   ^__^          \  (oo)\_______             (__)\       )\/\                 ||----w |                 ||     || 

如果你对牛不太感冒,那么还可以换成别的角色:

fortune | cowsay -f tux 
 _____________________________________ / You never know how many friends you \ | have until you rent a house on the  | \ beach.                              /  -------------------------------------    \     \         .--.        |o_o |        |:_/ |       //   \ \      (|     | )     /'\_   _/`\     \___)=(___/ 

想知道cowsay都支持哪些角色,输入下:

cowsay -l 
Cow files in /usr/share/cowsay/cows: apt beavis.zen bong bud-frogs bunny calvin cheese cock cower daemon default dragon dragon-and-cow duck elephant elephant-in-snake eyes flaming-sheep ghostbusters gnu head-in hellokitty kiss kitty koala kosh luke-koala mech-and-cow meow milk moofasa moose mutilated pony pony-smaller ren sheep skeleton snowman sodomized-sheep stegosaurus stimpy suse three-eyes turkey turtle tux unipony unipony-smaller vader vader-koala www 

我个人是比较喜欢剑龙:

fortune | cowsay -f stegosaurus 
 _________________________________________ / Q: What lies on the bottom of the ocean \ \ and twitches? A: A nervous wreck.       /  ----------------------------------------- \                             .       .  \                           / `.   .' "   \                  .---.  <    > <    >  .---.    \                 |    \  \ - ~ ~ - /  /    |          _____          ..-~             ~-..-~         |     |   \~~~\.'                    `./~~~/        ---------   \__/                        \__/       .'  O    \     /               /       \  "      (_____,    `._.'               |         }  \/~~~/       `----.          /       }     |        /    \__/             `-.      |       /      |       /      `. ,~~|                 ~-.__|      /_ - ~ ^|      /- _      `..-'                         |     /        |     /     ~-.     `-. _  _  _                      |_____|        |_____|         ~ - . _ _ _ _ _> 

总结

这篇文章不会传授你什么重要的知识或者提高你的Linux水平啥的,就是希望能你能稍微放松一下,有可能的话多探索一下你的系统。

原创文章转载请注明出处:Linux的10个经典彩蛋

英文原文链接