7 个好玩的 Linux 命令
玩具 命令

> 
> 这些好玩的 Linux 命令也有它的用处。
> 
> 
> 


![](/data/attachment/album/202111/16/164838m35s5q81t353sxq3.jpg "Woman sitting in front of her laptop")


Linux 的命令行可以说是资深用户和系统管理员的小窝。然而，Linux 不仅仅是大量的枯燥工作。Linux 是由爱玩的人开发的，他们还创造了一系列搞笑的命令。当你想轻松一下的时候，就可以自己试着这些。


### 蒸汽机车


随便什么时候，你可以使用 `sl` 命令使一辆<ruby> 蒸汽机车 <rt>  Steam Locomotive </rt></ruby>在你的终端上跑过。可以用你的软件包管理器安装这辆蒸汽机车。例如，在 Fedora 上可以这样：



```
$ sudo dnf install sl

```

![由符号和字符组成的蒸汽机车引擎图](/data/attachment/album/202111/16/164846dtk5uxc1u4l1xkmt.png "Steam locomotive")


#### 实际用途


据我所知，`sl` 命令确实只是为了好玩。你对 `sl` 有什么有趣的用途吗？请在评论中告诉我。


（LCTT 译注：`sl` 的实际用途就是提醒你 `ls` 打错了。?）


### 壁炉


点燃一座壁炉来温暖你的心和你的终端吧，`aafire` 命令会播放一段壁炉的动画。你可以用你的软件包管理器安装 `aafire`。在 Debian、Mint、 Elementary 之类的发行版上：



```
$ sudo apt install libaa-bin

```

在 Fedora、CentOS 之类的发行版：



```
$ sudo dnf install aalib

```

![由文字符号和字符组成的火的黑白图像](/data/attachment/album/202111/16/164846hwa9qabggbtbtwgj.png "fireside")


#### 实际用途


这个动画是向你的团队或老板传达一切即将化为乌有的微妙方式。


### 是的


你可以使用 `yes` 命令打印出一串文字，直到用 `Ctrl+C` 强行停止。例如，我是一个 Buffalo Bills 的球迷，所以我选择用 `yes` 命令打印出一串无尽的 “Buffalo Bills”：



```
$ yes Buffalo Bills

```

![画面上重复显示的是一行行 Buffalo Bills（左侧边缘略微被切断）](/data/attachment/album/202111/16/164847beg25y5da7dag4im.png "Yes command")


#### 实际用途


你可以用这个命令来向脚本输送确认信息，这样，当脚本停顿下来要求确认时，它就会自动收到 `yes`。例如，想象一下，你运行的一个脚本经常停下来问你确认：



```
$ foo
Are you sure you want to do this? Y/n  Y
Are you really sure? y/N  Y
But are you really? y/N

```

你可以通过向命令传递 `yes` 来自动接受这些信息：



```
$ yes | foo

```

另外，你也可以用 `yes` 来自动拒绝信息：



```
$ yes no | foo

```

### 命运


通过安装 `fortune` 命令，你可以就可以得到命运的指点。`fortune` 会打印出一段随机的、可能有意义的话语（LCTT 译注：来自命运的指点）。


用你的软件包管理器安装 `fortune`：



```
$ sudo apt install fortune

```

在 Fedora 上：



```
$ sudo dnf install fortune-mod

```

命运命令有许多数据集，它可以从中提取各种话语。例如，你可以从文学作品或科幻电视节目 《Firefly》中获得名人名言，或者从笑话、关于 Linux 的技巧等中选择。在你的资源库中搜索 `fortune`，看看你的发行版提供了哪些数据集。



```
$ fortune
Johnson's law:
  Systems resemble the organizations that create them.

```

#### 实际用途


你可以用命运来生成一个伪随机数。没有足够的熵来使它在密码学上安全，但当你需要一个意外的数字时，你可以用来计算字符或单词：



```
$ fortune | wc --chars
38
$ fortune | wc --words
8
$ fortune | wc --chars
169

```

### 彩虹猫


彩虹猫（`lolcat`）是一个将文件或标准输入连接到标准输出的程序（就像一般的 `cat` 命令），并在其中加入彩虹色。你可以用管道将其他命令的输出连接到 `lolcat`，这样就可以为结果加上彩虹色。


下面是 `lolcat -h` 的帮助输出的结果。


![屏幕上的文字被染成了彩虹的渐变色](/data/attachment/album/202111/16/164847mnzrh0rnhz0llenq.png "lolcat")


（LCTT 译注：我知道 `cat` 是 `catch`。）


### “FIG 来信”和横幅


“FIG 来信”（FIGlet）来源于 Frank、Ian 和 Glenn 信件中的签名艺术。这个命令（`figlet`）和横幅命令（`banner`）可以帮你创建简单的 ASCII 文本横幅。下面是一个 CentOS 系统的文本横幅：



```
$ figlet centos.com

```

![由符号和字符组成的阅读 “centos.com” 的文本横幅](/data/attachment/album/202111/16/164847yu3vwh3242pv5m18.png "figlet text banner")


将 `figlet` 连接到 `lolcat`，可以得到一个彩色的横幅：



```
$ figlet centos.com | lolcat

```

![用 lolcat 将 “centos.com” 的文字横幅渲染成彩虹色](/data/attachment/album/202111/16/164848ykcl3zl2kjs9cx34.png "Figlet with lolcat effects")



```
$ banner Hello World

```

![用英镑符号拼出的 “Hello World” 横幅](/data/attachment/album/202111/16/164848c0y2sqif4sqza3ia.png "Hello World banner")


#### 实际用途


`figlet` 和 `banner` 都是提醒用户他们正在登录的系统的简单方法。就像许多系统管理员、网页设计师和云开发人员一样，当你和几十台服务器一起工作时，这很有帮助。


### 电子语音


你可以通过安装电子语音（`espeak`）来为你的命令行添加语音功能。


一旦 `espeak` 安装完毕，调高你的电脑的音量，听你的机器和你说话，会有一些乐趣。电子语音是一个软件语音合成器，有几个不同的语音库可用：



```
$ espeak "Linux is the best operating system.”

```

### 有趣的命令


请查阅所有这些命令的手册，以探索所有的可能性和变化。你最喜欢哪些好玩的命令，它们在现实世界中是否也有用途？请在评论中分享你的最爱。




---


via: <https://opensource.com/article/21/11/fun-linux-commands>


作者：[Don Watkins](https://opensource.com/users/don-watkins) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
The Linux command line can be the home of power users and sysadmins. However, Linux is more than just a lot of hard work. Linux was developed by fun-loving people who created an array of comical commands. Try playing around with these yourself when you want a smile.

## Steam locomotive (sl)

For no reason whatsoever, you can cause a steam locomotive to zip across your terminal using the `sl`

command. Install Steam Locomotive with your package manager. For example, on Fedora:

`$ sudo dnf install sl`


![Steam locomotive A steam locomotive engine drawing made from symbols and characters](https://opensource.com/sites/default/files/uploads/locomotive_0.png)

### Real uses

As far as I know, the `sl`

command is truly just for fun. Do you have an interesting use for `sl`

? Let me know in the comments.

## Fireplace (aafire)

Warm your heart and your terminal with `aafire`

command, which causes a fireplace animation to play. You can install aafire with your package manager. On Debian, Mint, Elementary, and similar:

`$ sudo apt install libaa-bin`


On Fedora, CentOS, and others:

`$ sudo dnf install aalib`


![fireside A black and white image of a fire made from text symbols and characters](https://opensource.com/sites/default/files/uploads/fireside.png)

Don Watkins, CC BY-SA 4.0

### Real uses

This image is a subtle way to communicate to your team or boss that everything's about to go up in smoke.

## Yes

You can use the` yes`

command to print out a string of text until it is forcibly stopped with **Ctrl+C**. For example, I am a Buffalo Bills fan, so I chose to print out an endless series of Buffalo Bills with the `yes`

command:

`$ yes Buffalo Bills`


![Yes command A screenshot showing repeated lines of Buffalo Bills (left edge slightly cut off)](https://opensource.com/sites/default/files/uploads/bills.png)

Don Watkins, CC BY-SA 4.0

### Real uses

You can use this command to pipe confirmation to scripts so that when a script pauses to ask for confirmation, it automatically receives `yes`

. For example, imagine there's a script you run that often stops to ask you for confirmation:

```
$ foo
Are you sure you want to do this? Y/n Y
Are you really sure? y/N Y
But are you really? y/N
```


You can auto-accept such messages by passing `yes `

to the command:

`$ yes | foo`


Alternatively, you can auto-deny messages using yes as well:

`$ yes no | foo`


## Fortune

You can have your fortune told on the command line by installing Fortune. Fortune prints a random and possibly meaningful message.

Install Fortune with your package manager:

`$ sudo apt install fortune`


On Fedora:

`$ sudo dnf install fortune-mod`


The `fortune`

command has many datasets it can draw from. For instance, you can get famous quotes from literature or the science-fiction TV show *Firefly*, or choose from jokes, tips about Linux, and much more. Search your repository for "fortune" to see what options your distribution provides.

```
$ fortune
Johnson's law:
Systems resemble the organizations that create them.
```


### Real uses

You can use Fortune to generate a pseudo-random number. There's not enough entropy to make it cryptographically secure, but when you need an unexpected number, you can count characters or words:

```
$ fortune | wc --chars
38
$ fortune | wc --words
8
$ fortune | wc --chars
169
```


## Lolcat

Lolcat is a program that concatenates files, or standard input, to standard output (like the generic cat) and adds rainbow coloring to it. You can pipe the output of other commands to `lolcat,`

which provides a rainbow hue to the result.

Here's the result of `lolcat -h`

for its help output:

![lolcat onscreen text colored in a rainbow gradient](https://opensource.com/sites/default/files/uploads/lolcat_rainbow.png)

Don Watkins, CC BY-SA 4.0

## Figlet and banner

The `figlet`

and `banner`

commands let you create simple ASCII text banners. Here's a text banner for a CentOS system:

`$ figlet centos.com`


![figlet text banner Text banner reading "centos.com" composed from symbols and characters](https://opensource.com/sites/default/files/uploads/figlet_centos.png)

Don Watkins, CC BY-SA 4.0

Pipe `figlet`

to `lolcat`

for a colorful banner:

`$ figlet centos.com | lolcat`


![Figlet with lolcat effects A text banner reading "centos.com" made rainbow colored with lolcat](https://opensource.com/sites/default/files/uploads/lolcat_figlet_centos.png)

Don Watkins, CC BY-SA 4.0

`$ banner Hello World`


![Hello World banner A banner reading "Hello World" spelled out with pound symbols](https://opensource.com/sites/default/files/uploads/hello_world_0.png)

Don Watkins, CC BY-SA 4.0


### Real use

Both `figlet`

and `banner`

are easy ways to remind users what system they're logging on to, which can be helpful when you work with dozens of servers, as many sysadmins, web designers, and cloud developers do.

## Espeak

You can add speech capabilities to your command line funnies by installing `espeak`

.

Once `espeak`

is installed, turn up the volume on your computer and have some fun listening to your machine talk to you. Espeak is a software speech synthesizer, and there are a few different voice libraries available.

`$ espeak "Linux is the best operating system."`


## Fun commands

Be sure to consult the man pages of all these commands to explore all the possibilities and iterations. What are your favorite silly commands, and do they have real-world uses as well? Share your favorites in the comments.

## 11 Comments