哞~ 我的 Linux 终端里有头牛
cowsay
![](/data/attachment/album/202306/28/225311tkxprbpbv44zpta9.jpg)



> 
> cowsay 是一个有趣的小型 Linux 命令行实用程序，它有各种使用方式。以下是几个示例。
> 
> 
> 


如果你想的话，Linux 终端可以是一个有趣的地方。


当然，终端一般用在严肃的场合，但你可以使用 [有趣的 Linux 命令](https://itsfoss.com/funny-linux-commands/) 来娱乐自己。


`cowsay` 就是其中之一。它可以在终端上显示一头牛。


![Linux 中的 cowsay 命令](/data/attachment/album/202306/28/225340xtm8dd70dt098mqf.png)


`cowsay` 的一个特点是，如果与其他命令组合使用，它可以用于一些 “严肃的场合”。比如，在共享的 Linux 服务器上使用它来显示 “每日消息”，以供多个用户查看。


听起来有趣吗？是时候~~喂养~~安装一个了。


### 安装 Cowsay


`cowsay` 是一个受欢迎的工具，它可以在大多数 Linux 发行版的软件仓库中找到。


要在 Debian 和 Ubuntu 系统上安装 `cowsay`，请打开终端并运行：



```
sudo apt install cowsay

```

对于 Fedora，请使用：



```
sudo dnf install cowsay

```

在基于 Arch Linux 的发行版中，请使用：



```
sudo pacman -S cowsay

```

### 使用 Cowsay


顾名思义，这是一头以 ASCII 艺术展示的牛，能输出输入的文本。默认情况下，`cowsay` 提供了几个选项来调整这头 ASCII 牛的外观和样式。


#### 普通的 cowsay



```
cowsay <文本>

```

这将在牛讲话的气泡中打印你提供的任何文本。


![默认的 cowsay 命令](/data/attachment/album/202306/28/225341v1111wrbvj17pd6r.svg)


或者，你可以使用管道重定向，将另一个命令（比如 `echo`）的输出作为 `cowsay` 的输入。



```
echo "Hello" | cowsay

```

#### 贪婪的牛


这里，牛的眼睛看起来有点贪婪，它是美元符号。



```
cowsay -g <消息>

```

![具有贪婪选项的 cowsay 命令](/data/attachment/album/202306/28/225341k9a7dktd3ld8jrj9.svg)


#### 使用特殊字符作为眼睛


你可以使用 `-e` 选项，然后提供你希望作为眼睛的两个字符。默认是 `OO`。



```
cowsay -e hh Hello

```

![具有自定义眼睛字符的 cowsay 命令](/data/attachment/album/202306/28/225341fm69cbb7y4dv1bmy.svg)


在上面的截图中，两个 `h` 将出现在眼睛的位置。



> 
> ? 如果你输入的字符已被任何默认选项使用，比如 `$$`，那么它将被覆盖。
> 
> 
> 


#### 使用其他字符代替牛


`cowsay` 还提供了许多其他 ASCII 图像，你可以通过 `-f` 选项使用它们。


使用 `-l` 选项列出它们：



```
cowsay -l

```

![使用 "ls /usr/share/cowsay/cows/" 和 "cowsay -l" 列出的各种默认 cowsay 图像](/data/attachment/album/202306/28/225341v98gj4biqem98j9o.png)


现在，要打印上述图像之一，请使用：



```
cowsay -f <牛文件名称> <消息>

```

![使用不同图像而不是默认的牛的 cowsay 命令](/data/attachment/album/202306/28/225342sao7ao8padhr5h7p.svg)


类似地，在更新的版本中，你可以使用 `-r` 选项随机打印上述图像之一。



```
cowsay -r Hello

```

#### 其他选项




| 选项 | 用途 |
| --- | --- |
| `-b` | 启用博格模式 |
| `-d` | 看起来死了的牛 |
| `-p` | 陷入偏执状态的牛 |
| `-s` | 看起来迷迷糊糊的牛 |
| `-t` | 一只疲倦的牛 |
| `-y` | 让牛年轻一些 |


### 使用 Cowthink


`cowthink` 是与 `cowsay` 一起提供的辅助程序。它显示的是思维泡泡而不是说话泡泡。如果你熟悉漫画书的标注，这将更有意义。



```
cowthink Hello

```

![默认的 Cowthink 命令](/data/attachment/album/202306/28/225342umbnamo0w1lo33sw.svg)


所有在 `cowsay` 中提到的选项在这里同样适用。


### 使用 Cowsay 和 Fortune


通过管道重定向，你可以将 `cowsay` 与另一个流行的有趣的 Linux 命令 `fortune` 结合使用。



> 
> ? 在 Ubuntu 中可以使用 `sudo apt install fortune lolcat` 命令安装 `fortune` 和 `lolcat`。
> 
> 
> 


对于那些不知道 `fortune` 是什么的人来说，它是一个小程序，在终端上打印名人名言。你可以像这样作为独立命令来运行它：



```
fortune

```

要使用 `cowsay` 打印 `fortune` 的内容，运行：



```
fortune | cowsay

```

![](/data/attachment/album/202306/28/225343biqozp6nnizippgi.svg)


你还可以添加 `cowsay` 的选项来使输出更好：



```
fortune | cowsay -f dragon

```

### 用 lolcat 把牛变成彩色的


许多人都熟悉 `lolcat` 给文本添加的彩虹效果。那么为什么不将其与上述程序一起使用呢？你只需要将 `cowsay` 命令连接到 `lolcat` 命令上即可。



```
cowsay Hello | lolcat

```

![运行 cowsay 和 lolcat](/data/attachment/album/202306/28/225343z965rg8ubufn8s9b.svg)


现在，如果你想同时添加 `fortune` 和各种 `cowsay` 选项，请使用所有这些选项，并将整个命令的输出都连接到 `lolcat`，就像这样：



```
fortune | cowsay -f tux | lolcat
fortune | cowthink -f tux | lolcat

```

![在一起运行 fortune、cowsay 和 lolcat](/data/attachment/album/202306/28/225343by7fry477k66o5z1.svg)


### 第三方牛文件（适用于高级用户）


对默认的 `cowsay` 牛文件不感兴趣吗？别担心，有许多不同的牛文件可供选择，由热心的开发者创建。我在这里介绍两个：<https://github.com/bkendzior/cowfiles> 和 <https://github.com/paulkaefer/cowsay-files>。


你可以按照它们的 `README` 所述从这些存储库安装牛文件，或者只需从存储库中下载所需的牛文件（.cow）并将它们粘贴到 `/usr/share/cowsay/site-cows/` 下。现在，你可以通过文件名访问该牛文件：



```
cowsay -f <新文件名> Hello

```

在屏幕截图中，你可以看到我使用了一个下载下来的牛文件，名为 `C3PO.cow`。


对于那些想要创建自己的图像的人，可以访问 [Charc0al 的 cowsay 文件](https://charc0al.github.io/cowsay-files/converter/)。


![第三方牛文件](/data/attachment/album/202306/28/225344kr3gj7gqkbr8vrgq.png)


在这里，你可以下载现有的文件，或者转换一些图像（建议不大于 50×50）以满足需求。


### 其他有趣的用法


#### 使用 cowsay 提示输入 sudo 命令的密码



```
sudo -p "$(cowsay '如果你知道密码，请在此输入。否则请离开：')" <command>

```

![Cowsay sudo 提示](/data/attachment/album/202306/28/225345qz2mrrvlmzxltk0x.svg)


#### 将 cowsay 作为 bash 配置的一部分，以便在每次打开终端时看到欢迎


对于像 Fedora 中的较新版本的 `cowsay`，可以将 `fortune | cowsay -r | lolcat` 添加到你的 `~/.bashrc` 中。现在，每次打开终端时，都会打印一个带有不同名言的新牛文件。


对于没有随机选项（`-r`）的较旧版本的 `cowsay`，你可以手动获取不同的文件，并使用 `fortune | cowsay -f <要使用的特定牛文件的名称> | lolcat`。


#### 使用 cowsay 显示其他命令的输出


你可以让 `lsblk` 等命令使用 `cowsay` 打印输出。只需将这些命令连接起来。



```
lsblk | cowsay

```

#### 在 Fedora 中使用 cowsay-beefymiracle


`beefymiracle` 是 Fedora 中提供的一个 cowsay 包。这里的牛变成了牛肉（我这颗素食主义者的心在哭泣 ?）。


使用下面的命令来安装它：



```
sudo dnf install cowsay-beefymiracle

```

现在，运行：



```
cowsay -f beefymiracle <消息>

```

![cowsay 的 beefymiracle 文件](/data/attachment/album/202306/28/225345c509znmnncntdm5v.png)


### 更多：XCowsay


`xcowsay` 是普通的 cowsay 的图形替代品。这里，牛不再是 ASCII 图形，而是一个真实的图像。你可以通过以下方式进行安装：



```
sudo apt install xcowsay

```

现在运行：



```
xcowsay <消息>

```

这将根据文本的长度，在一段特定的时间内显示图形化的牛，然后消失，**但你可以点击它立即隐藏。**


![xcowsay 命令](/data/attachment/album/202306/28/225346v0lccv0q1dd9l1cq.png)


更有趣的是，牛可以“梦见”图像而不是文本。甚至牛的图像可以更改为随机图像。


使用以下命令之一：



```
xcowsay --dream=file

```

或者



```
xcowsay --image=file --dream=file

```

![](/data/attachment/album/202306/28/225347qvqayvvrqnnscfvn.png)


![](/data/attachment/album/202306/28/225347ktzu3ri7opjto6yj.png)


你可以查看 `xcowsay` 的手册页面以了解更多选项。


### 更多终端中的 ASCII 乐趣


喜欢 ASCII 艺术吗？可以尝试用 [Neofetch](https://itsfoss.com/using-neofetch/) 以 ASCII 格式显示你所使用的发行版的徽标。


为什么只限于徽标呢？Linux 终端上还有很多 ASCII 工具。


不要停止在终端中寻找乐趣。


希望你喜欢这篇关于以各种格式使用 `cowsay` 的教程。惊人的是，这个小工具提供了如此多的选项，有这么多的使用方式。


你最喜欢哪个 cowsay 的例子？不要说牛肉的那个 ?


*（题图：MJ/bd304f28-2476-4496-93d2-50fdae0a8831）*




---


via: <https://itsfoss.com/cowsay/>


作者：[Sreenath](https://itsfoss.com/author/sreenath/) 选题：[lkxed](https://github.com/lkxed/) 译者：ChatGPT 校对：[wxy](https://github.com/wxy)


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


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

The Linux terminal can be a fun place if you want it to be.

Of course, it is used for serious work but you have [funny Linux commands](https://itsfoss.com/funny-linux-commands/) to amuse yourself.

The cowsay is one such tool. It gives you a cow in the terminal.

![Cowsay command in Linux](https://itsfoss.com/content/images/2023/06/cowsay-linux.png)

The thing about cowsay is that it could be used for 'serious work' if combined with other commands. One such example is using it to display the 'message of the day' on a shared Linux server with multiple users.

Sounds interesting? Time to ̶m̶i̶l̶k̶ install it.

## Install Cowsay

Cowsay is a popular tool and it is available in the repositories of most Linux distributions.

To install cowsay in Debian and Ubuntu system, open a terminal and run:

`sudo apt install cowsay`


For Fedora, use:

`sudo dnf install cowsay`


And in Arch Linux based distros, use:

`sudo pacman -S cowsay`


## Using Cowsay

As the name suggests, this is an ASCII talking cow, that outputs text provided as its input. By default, cowsay provides several options to tweak the look and appearance of the ASCII cow.

### Normal Cowsay

`cowsay <Text>`


This will print whatever text you provided in a speechbubble with the cow .

Or you can provide output of another command, say `echo`

as input to cowsay using pipes redirection.

`echo "Hello" | cowsay`


### Greedy Cow

Here, cow appears to be greedy, with Dollar eyes.

`cowsay -g <message>`


### Use Special Characters as eyes

You can use the `-e`

option, and then provide two characters that you want to appear as eyes. The default is “OO”.

`cowsay -e hh <hello>`


Here, in the above screenshots, two “h” will appear in place of eyes.

### Use another character instead of the cow

Cowsay provides many other ASCII images also, which you can use through the option `-f`

.

List them with option `-l`

:

`cowsay -l`


![Various default cowsay cow files listed using "ls /usr/share/cowsay/cows/" and "cowsay -l"](https://itsfoss.com/content/images/2023/06/cowsay-files.png)

Now, to print one of the above images, use:

`cowsay -f <cowfile name> <message>`


Similarly, in newer versions, you can use `-r`

option to randomly print one of the above images.

`cowsay -r Hello`


### Other options

Option | Use |
---|---|

-b | Invokes Borg mode |

-d | Causes the cow to appear dead |

-p | Causes a state of paranoia to come over the cow |

-s | Makes the cow appear thoroughly stoned |

-t | A tired cow |

-y | Brings on the cow’s youthful appearance |


## Using Cowthink

Cowthink is an adjoint program that come with cowsay. Instead of the speach bubble, it displays the thought bubble. It will make more sense to you if you are familiar with comic book notations.

`cowthink Hello`


All the options that were mentioned with cowsay will work here as well.

## Using Cowsay with Fortune

With the help of pipe redirection, you can use cowsay along with another popular fun Linux command, the `fortune`

command.

`sudo apt install fortune lolcat`

For those of you, who don’t know what `fortune`

, it is a small program, that prints quotes from famous persons on a terminal. You can run it as a standalone command like:

`fortune`


To simply print what fortune says using cowsay, run:

`fortune | cowsay`


You can also add the cowsay options to make it better:

`fortune | cowsay -f dragon `


## Using a colorful cow with lolcat

Many of you know lolcat and its rainbow effects on texts. So why not use it along with the above programs? All you have to do is to pipe the cowsay command to lolcat.

`cowsay Hello | lolcat`


Now, if you want to add `fortune`

and various `cowsay`

options along with this, use all such options and pipe the entire thing to lolcat, like this:

```
fortune | cowsay -f tux | lolcat
fortune | cowthink -f tux | lolcat
```


## Third-party cow files (for advanced users)

Not interested in the default cowsay cow files? Do not worry, there are a huge number of different cowfiles out there, created by enthusiast developers. Two of them, I will mention here. [https://github.com/bkendzior/cowfiles](https://github.com/bkendzior/cowfiles) and [https://github.com/paulkaefer/cowsay-files](https://github.com/paulkaefer/cowsay-files)

You can either install the cowfiles from these repositories as mentioned on their README, or just download the required cowfile (.cow) from the repository and paste them on `/usr/share/cowsay/site-cows/`

. Now, you can access that cowfile using its name:

`cowsay -f <new file name> Hello`


You can see in the screenshot I have used a downloaded cow file, called C3PO.cow.

For those of you, who want to create your own images, you can visit [Charc0al’s cowsay file](https://charc0al.github.io/cowsay-files/converter/).

![Third Party cowfiles](https://itsfoss.com/content/images/2023/06/charcoal-cowfiles.png)

Here, you can either download the existing files, or convert some of your images (recommend no larger than 50 × 50) for the purpose.

## Other funny uses

**Use cowsay prompt to enter password in sudo commands:**

`sudo -p "$(cowsay 'If you know the password, enter it here. Or just go away:')" <command>`


**Make cowsay as an entry to your bash config, so you are greeted every time you open the terminal.**

- For newer cowsay versions, like those in Fedora, add
`fortune | cowsay -r | lolcat`

to your`~/.bashrc`

. Now, each time, you open the terminal, a new cowfile with a different quote will be printed. - For older versions of cowsay, where you cannot get the random (-r) option, you can get different files manually, and use
`fortune | cowsay -f <name of particular cowfile to use> | lolcat`

.

**Make other commands show output using cowsay**

You can make commands like `lsblk`

to print the output using cowsay. Just pipe those commands.

`lsblk | cowsay`


**Use cowsay-beefymiracle in Fedora**

`beefymiracle`

is a cowsay package available in Fedora. The cow is turned into beef here (my vegetarian heart cries 😢).

Use the below command to install it:

`sudo dnf install cowsay-beefymiracle`


Now, run:

`cowsay -f beefymiracle <message>`


![cowsay beefymiracle file](https://itsfoss.com/content/images/2023/06/cowsay-beefymiracle-fedora.png)

## Bonus: XCowsay

`xcowsay`

is a graphical alternative to the normal cowsay. Here, the cow is no more ASCII, but a proper image. You can install it by:

`sudo apt install xcowsay`


Now run:

`xcowsay <message>`


This will display the graphical cow for a specific amount of time according to the length of the text, and then disappears. **You can click on it to hide it immediately, though.**

![xcowsay command](https://itsfoss.com/content/images/2023/06/xcowsay-normal.png)

`xcowsay`

commandWhat is more interesting is the cow can 'dream' images instead of texts. Or even the cow image can be changed to random images.

Use either:

```
xcowsay --dream=file
OR
xcowsay --image=file --dream=file
```


![](https://itsfoss.com/content/images/2023/06/custom-image-in-xcowsay.png)

![](https://itsfoss.com/content/images/2023/06/xcowsay-random-image-both.png)

You can explore the man page of `xcowsay`

for more options.

## More ASCII fun in the terminal

Love ASCII? How about displaying your distribution's logo in ASCII format with [Neoftech](https://itsfoss.com/using-neofetch/)?

[Display Linux Distribution Logo in ASCII Art in TerminalWondering how they display Linux logo in terminal? With these tools, you can display logo of your Linux distribution in ASCII art in the Linux terminal.](https://itsfoss.com/display-linux-logo-in-ascii/)![](https://itsfoss.com/content/images/wordpress/2015/10/display-linux-logo-ascii-terminal.jpeg)


![](https://itsfoss.com/content/images/wordpress/2015/10/display-linux-logo-ascii-terminal.jpeg)

Why restrict with logo? Here are more ASCII tools for Linux terminal.

[10 Tools to Generate and Have Fun With ASCII Art in Linux TerminalLinux terminal is not as scary as you think. Of course, it could be intimidating in the beginning but once you know the terminal better, you start loving it. You are likely to use the terminal for serious work. But there are many fun stuff you can do in the](https://itsfoss.com/ascii-art-linux-terminal/)![](https://itsfoss.com/content/images/wordpress/2022/07/ascii-art-tools-linux.png)


![](https://itsfoss.com/content/images/wordpress/2022/07/ascii-art-tools-linux.png)

Don't stop the fun in the terminal.

[12 Linux Commands to Have Some Fun in the TerminalSo, you think Linux terminal is all work and no fun? These funny Linux commands will prove you wrong. The Linux terminal is the place to get serious work done. We have plenty of useful linux command tips and tricks to help you with that. But, did you know that](https://itsfoss.com/funny-linux-commands/)![](https://itsfoss.com/content/images/wordpress/2020/04/fun-linux-commands.png)


![](https://itsfoss.com/content/images/wordpress/2020/04/fun-linux-commands.png)

I hope you liked this tutorial on using cowsay in various formats. It's amazing that this little tool comes with so many options and there are so many ways to use it.

Which cowsay example did you like the most here? Don't say beef one 💔