Total Pageviews

Saturday, 1 April 2023

有趣的 Linux 命令行工具

 

Linux is fun! Huhhh. OK so you don't believe me. Mind me at the end of this article you will have to believe that Linux is actually a fun box.
Linux 是非常有趣的,别不相信 —— 看完这篇文章,你一定会发现 Linux 系统神奇的用法。
请注意,下面部分命令给出了两种包管理软件的安装方式,如果是 Debian 系的系统,请使用 apt,如果是 Red Hat 系的系统,请使用 yum。如果你使用了其他 Linux 发行版,或使用了其他包管理工具(例如 macOS 上的 brew),可能无法找到所有这些命令。
注:为了在代码块中区别输入输出,以 $ 开头的行代表输入,其它行代表输出。

curl

命令:curl
curl 用于互联网传输数据,支持多种协议。通过以下命令可以查看天气:

$ curl -4 http://wttr.in

sl (Steam Locomotive)

命令:sl(蒸汽机车的缩写)
You might be aware of command 'ls' the list command and use it frequently to view the contents of a folder but because of miss-typing sometimes you would result in 'sl', how about getting a little fun in terminal and not command not found.
你一定知道 ls 是用来显示文件夹内容的常见命令,但如果不小心打成 sl 呢?通过包管理工具安装它,你就能看见一辆跑过屏幕的火车,而不是「找不到命令」:

$ apt install sl #In Debian like OS, or aptitude based system
$ yum install sl #In Red Hat like OS, or yum based system
$ sl

This command works even when you type 'LS' and not 'ls'.

telnet

命令:telnet
No! No!! it is not as much complex as it seems. You would be familiar with telnet. Telnet is a text-oriented bidirectional network protocol over network. Here is nothing to be installed. What you should have is a Linux box and a working Internet.
不!它并不像看上去那样复杂。你会熟悉它的。Telnet 是一个基于文本的双向网络协议。你无需安装它,只需要一台能够联网的 linux 机器就行。


而以下命令将会在你的命令行中生成一个 ASCII 世界地图:

$ telnet mapscii.me

是不是很有趣?

fortune

命令:fortune What about getting your random fortune, sometimes funny in
terminal.
在终端获取随机的人生经验,听上去不错吧?

$ apt install fortune
$ yum install fortune
$ fortune

You're not my type. For that matter, you're not even my species!!!
Future looks spotty. You will spill soup in late evening.
You worry too much about your job. Stop it. You are not paid enough to worry.
Your love life will be... interesting.

rev (Reverse)

命令:rev(反转的缩写)
It reverse every string given to it, is not it funny.
它会反转任何输入的字符串,然后输出。

$ rev

123abc
cba321
xuniL eb ot nrob
born to be Linux

factor

命令:factor Time for some Mathematics, this command output all the possible factors of a given number.
数学时间到:这个命令会输出一个数字的所有质因数。

$ factor 5

5
5: 5
12
12: 2 2 3
1001
1001: 7 11 13
5442134
5442134: 2 2721067

script

shell 脚本
OK fine this is not a command and a script but it is nice.
它会输出乘法口诀表。

$ for i in {1..9}; do for j in $(seq 1 $i); do echo -ne $i*$j=$((i*j))\\t;done; echo;done

1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81

cowsay

命令:cowsay
An ASCII cow in terminal that will say what ever you want.
一个终端里由 ASCII 码组成的牛,你想让它说什么,它就会说什么。

$ apt install cowsay
$ yum install cowsay
$ cowsay I Love *nix

_____________
< I Love *nix >
-------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

How about pipelineing 'fortune command', described above with cowsay?
通过管道指令将 fortune 命令的输出作为 cowsay 的输入:

$ fortune | cowsay

_________________________________________
/ Q: How many Oregonians does it take to \
| screw in a light bulb? A: Three. One to |
| screw in the light bulb and two to fend |
| off all those |
| |
| Californians trying to share the |
\ experience. /
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

Note: '|' is called pipeline instruction and it is used where the output of one command needs to be the input of another command. In the above example the output of 'fortune' command acts as an input of 'cowsay' command. This pipeline instruction is frequently used in scripting and programming.
注意:'|' 被称为管道指令,用于将一个命令的输出作为另一个命令的输入。在上面的例子中,fortune 命令的输出作为 cowsay 命令的输入。管道指令经常用于脚本和编程。
xcowsay is a graphical program which response similar to cowsay but in a graphical manner, hence it is X of cowsay.
xcowsay 是一个图形程序,其效果类似于 cowsay,但是是以图形方式显示说话的牛。

$ apt install xcowsay
$ xcowsay I Love nix

cowthink is another command, just run cowthink Linux is sooo funny and see the difference in output of cowsay and cowthink. cowthink 是另一个命令,你可以执行 cowthink Linux is sooo funny 看看它和 cowthink 的输出差异。

$ apt install cowthink
$ brew install cowthink
$ cowthink ....Linux is sooo funny

_________________________
( ....Linux is sooo funny )
-------------------------
o ^__^
o (oo)\_______
(__)\ )\/\
||----w |
|| ||

注:你可以查看以上命令的帮助菜单,可以把牛换成其他会说话的动物。

yes

命令:yes
It is funny but useful as well, specially in scripts and for System Administrators where an automated predefined response can be passed to terminal or generated.
它很有趣,也很实用。使用 yes,终端将会不断输出你所输入的字符串。

$ yes I Love Linux

I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux
I Love Linux

Note: (Till you interrupt i.e Ctrl+C).
直到你使用 Ctrl+C 结束它,否则会一直输出。

toilet

命令:toilet
What? Are u kidding, huhh no! Definitely not, but for sure this command name itself is too funny, and I don't know from where this command gets it's name.
什么?你在开玩笑吗,不!绝对不是,但肯定这个命令名称本身太有趣了,我不知道这个命令从哪里得到它的名字。

$ apt install toilet
$ brew install toilet
$ toilet mimi

" "
mmmmm mmm mmmmm mmm
# # # # # # # #
# # # # # # # #
# # # mm#mm # # # mm#mm

It even offers some kind of color and fonts style.
它甚至提供了颜色和字体样式。

$ toilet -f mono12 -F metal mimi.com

Note: Figlet is another command that more or less provide such kind of effect in terminal.
注意:Figlet 是另一个或多或少在终端提供这种效果的命令。

cmatrix

命令:cmatrix
You might have seen Hollywood movie 'matrix' and would be fascinated with power, Neo was provided with, to see anything and everything in matrix or you might think of an animation that looks alike Hacker's desktop.
你可能已经看过好莱坞电影《黑客帝国》,并且会被 Neo 获取的力量所吸引 —— 在矩阵中看到一切;或许你也会想到一个看起来和 Hacker 的桌面一样的动画。

$ apt install cmatrix
$ brew install cmatrix
$ cmatrix

yum 上似乎找不到,可以使用源码编译安装。

oneko

命令:oneko
OK so you believe that mouse pointer of Linux is the same silly black/white pointer where no animation lies then I fear you could be wrong. oneko is a package that will attach a "Jerry" with you mouse pointer and moves along with you pointer.
如果你觉得 Linux 的鼠标就是一个愚蠢的黑色 / 白色指针,而没有动画,我担心你可能是错的。使用 oneko 命令,就可以创造一只与你的鼠标指针玩耍的猫。

$ apt install oneko
$ yum install oneko
$ oneko

Note: Once you close the terminal from which oneko was run, jerry will disappear, nor will start at start-up. You can add the application to start up and continue enjoying.
注意:一旦你关闭了运行 oneko 的终端,小猫就会消失。你可以把它添加到开机启动中,继续享受撸猫的乐趣。

while

命令:while
The below while command is a script which provides you with colored date and file till you interrupt (Ctrl+C). Just copy and paste the below code in terminal.
下面的 while 命令是一个脚本,它会为你提供彩色日期和文件,直到你用 Ctrl+C 中断。只需在终端中复制并粘贴以下代码即可。

$ while true; do echo "$(date '+%D %T' | toilet -f term -F border --gay)"; sleep 1; done

Note: The above script when modified with following command, will gives similar output but with a little difference, check it in your terminal.
注意:上面的脚本在使用以下命令修改后,会给出类似的输出,但有一点区别,请在终端中检查它。

$ while true; do clear; echo "$(date '+%D %T' | toilet -f term -F border --gay)"; sleep 1; done

espeak

命令:espeak
Just Turn the Knob of your multimedia speaker to full before pasting this command in your terminal and let us know how you felt listening the god's voice.
在将此命令粘贴到终端之前,请将你的音箱音量开到最大,让我们知道你是如何聆听上帝的声音的。

$ apt install espeak
$ yum install espeak
$ espeak "This is a very good website dedicated to Foss Community"

aafire

命令:aafire
How about fire in your terminal. Just type aafire in the terminal, without quotes and see the magic. Press any key to interrupt the program.
在你的终端放火,听上去如何?只需在终端输入 aafire,就可以看到神奇的现象。按任意键中断程序。

$ apt install libaa-bin
$ aafire

bb

命令:bb
First install apt insatll bb and then, type bb in terminal and see what happens.
首先用 apt 安装 bb 命令,然后在终端输入 bb,看看会发生什么。

$ apt install bb
$ bb

注:需要图形界面。

url

命令:url
Won't it be an awesome feeling for you if you can update you twitter status from command line in front of your friend and they seems impressed. OK just replace username, password and your status message with your's username, password and "your status message".
如果你可以在你的朋友面前通过命令行更新你的 Twitter 状态,这绝对是超棒的感觉 —— 而且他们也会印象深刻。好的,只需把下面的 YourUsername,YourPassword 和 Your status message 替换为你自己的用户名,密码和状态信息即可。

$ url -u YourUsername:YourPassword -d status="Your status message" http://twitter.com/statuses/update.xml

ASCIIquarium

命令:ASCIIquarium
How it will be to get an aquarium in terminal.
怎样才能在终端获得一个水族馆?

$ apt install libcurses-perl
$ cd /tmp
$ wget https://cpan.metacpan.org/authors/id/K/KB/KBAUCOM/Term-Animation-2.4.tar.gz
$ tar -zxvf Term-Animation-2.4.tar.gz
$ cd Term-Animation-2.4
$ perl Makefile.PL && make && make test
$ make install

Now Download and Install ASCIIquarium.
现在下载并安装 ASCIIquarium。

$ cd /tmp
$ wget https://robobunny.com/projects/asciiquarium/asciiquarium.tar.gz
$ tar -zxvf asciiquarium.tar.gz
$ cd asciiquarium_1.1
$ cp asciiquarium /usr/local/bin
$ chmod 0755 /usr/local/bin/asciiquarium

And finally run asciiquarium or /usr/local/bin/asciiquarium in terminal without quotes and be a part of magic that will be taking place in front of your eyes.
最后在终端中运行 asciiquarium,水族馆便展现在你面前。

$ asciiquarium

更多

Have fun, you can say me thanks later :) yup your comment is highly appreciated which encourages us write more. Tell us which command you liked the most. Stay tuned i will be back soon with another article worth reading.

本文翻译自:20 Funny Commands of Linux or Linux is Fun in Terminal

拓展阅读:
扫盲 Linux&UNIX 命令行 —— 从 “电传打字机” 聊到 “shell 脚本编程”
计算机领域有哪些经典的典故或笑话?
一行代码可以做什么?
the-art-of-command-line

No comments:

Post a Comment