在 Linux 命令行上拥有一头奶牛
cowsay

> 
> 使用 cowsay 实用程序将牛的话语带到你的终端输出。
> 
> 
> 


![](/data/attachment/album/201812/14/132737a4vjqeyp1ndm41vw.png)


欢迎来到 Linux 命令行玩具第四天。如果这是你第一次访问这个系列，你可能会问自己，什么是命令行玩具。我们也在考虑这一点，但是一般来说，这可能是一个游戏，或者任何简单的娱乐，可以帮助你在终端玩得开心。


你们中的一些人会见过我们之前的选中的各种玩具，但是我们希望至少有一个对每个人来说都是新的。因为几乎所有我告诉他这个系列的人都已经问过它了，所以今天的选中的玩具是必须提及的。


你也不会认为我们会在不提及 `cowsay` 的情况下完成这个系列，对吧？


`cowsay` 是一个神奇的实用程序，它将文本作为 ASCII 艺术牛的讲话文本输出。


你可能会发现 `cowsay` 打包在你的默认存储库中，甚至可能已经安装了。对我来说，在 Fedora，像这样安装:



```
$ sudo dnf install -y cowsay
```

然后，用 `cowsay` 调用它，然后是你的消息。也许你想到昨天我们谈到的 [fortune 应用](https://opensource.com/article/18/12/linux-toy-fortune) 连接起来。



```
$ fortune | cowsay
 _________________________________________
/ If at first you do succeed, try to hide \
\ your astonishment.                      /
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
```

就这样！`cowsay` 还有点小变体，称为 cow 文件，通常可以在 `/usr/share/cowsay` 找到 ，要查看系统上可用的 cow 文件，请在 `cowsay` 之后使用 `-l` 。然后，用 `-f` 试试其中之一。



```
$ cowsay -f dragon "Run for cover, I feel a sneeze coming on."
 _______________________________________
/ Run for cover, I feel a sneeze coming \
\ on.                                   /
 ---------------------------------------
      \                    / \  //\
       \    |\___/|      /   \//  \\
            /0  0  \__  /    //  | \ \    
           /     /  \/_/    //   |  \  \  
           @_^_@'/   \/_   //    |   \   \ 
           //_^_/     \/_ //     |    \    \
        ( //) |        \///      |     \     \
      ( / /) _|_ /   )  //       |      \     _\
    ( // /) '/,_ _ _/  ( ; -.    |    _ _\.-~        .-~~~^-.
  (( / / )) ,-{        _      `-.|.-~-.           .~         `.
 (( // / ))  '/\      /                 ~-. _ .-~      .-~^-.  \
 (( /// ))      `.   {            }                   /      \  \
  (( / ))     .----~-.\        \-'                 .~         \  `. \^-.
             ///.----..>        \             _ -~             `.  ^-`  ^-_
               ///-._ _ _ _ _ _ _}^ - - - - ~                     ~-- ,.-~
                                                                  /.-~
```

我对 `cowsay` 的真正不满是，我今天没有足够的时间来为牛的挤奶 —— 一语双关。牛排价格太高了，我只是开个玩笑。


更严重的是，我已经完全忘记了 `cowsay` 直到我在学习 Ansible 的剧本时再次遇到它。如果你碰巧安装了 `cowsay`，当你运行Ansible 的剧本时，你会从一队奶牛那里获得输出。例如，运行这个剧本：



```
- hosts:
    - localhost
  tasks:
    - action: ping
```

可能会给你以下信息：



```
$ ansible-playbook playbook.yml
 __________________
< PLAY [localhost] >
 ------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

 ________________________
< TASK [Gathering Facts] >
 ------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ok: [localhost]
 _____________
< TASK [ping] >
 -------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ok: [localhost]
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

localhost                  : ok=2    changed=0    unreachable=0    failed=0  
```

`cowsay` 在 GPLv3 许可证下可用，您可以在 GitHub 上找到 它的 Perl [源代码](https://github.com/tnalpgge/rank-amateur-cowsay)。我也见过其他语言的版本，所以可以看看其他变体；例如，这是 [R 语言版](https://github.com/sckott/cowsay)。用你选择的语言实现你自己的版本可能是一项有趣的编程学习任务。


既然讲完了 `cowsay`，我们可以去更绿色的牧场了。


你有希望我来介绍的喜欢的命令行玩具吗？这个系列的排期大部分都填好了，但我还有一些空位方。在下面的评论中让我知道，我会来看看。如果有空间，我会尝试把它包括进去。如果没有，但是我收到了一些好的意见，我在结尾提及。


看看昨天的玩具，[如何给你的 Linux 终端带来好运](https://opensource.com/article/18/12/linux-toy-fortune)，明天再来看看另一个！




---


via: <https://opensource.com/article/18/12/linux-toy-cowsay>


作者：[Jason Baker](https://opensource.com/users/jason-baker) 选题：[lujun9972](https://github.com/lujun9972) 译者：[heguangzhi](https://github.com/heguangzhi) 校对：[wxy](https://github.com/wxy)


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


OK
Welcome to the fourth day of the Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself, what’s a command-line toy. We’re figuring that out as we go, but generally, it could be a game, or any simple diversion that helps you have fun at the terminal.


Some of you will have seen various selections from our calendar before, but we hope there’s at least one new thing for everyone. Because just about everyone who I’ve mentioned this series to has asked me about it already, today’s selection is an obligatory one.

You didn’t think we’d make it through this series without mentioning cowsay, did you?

Cowsay is an udderly fantastic utility that takes text and outputs it as the spoken text of an ASCII-art bovine.

You’ll likely find cowsay packaged in your default repositories, and perhaps even already installed. For me, in Fedora, all it took to install was:

`$ sudo dnf install cowsay`


Then, invoke it with cowsay followed by your message. Perhaps you’d like to pipe in the [fortune ](https://opensource.com/article/18/12/linux-toy-fortune)[utility](https://opensource.com/article/18/12/linux-toy-fortune) we talked about yesterday.

```
$ fortune | cowsay
_________________________________________
/ If at first you do succeed, try to hide \
\ your astonishment. /
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
```


That’s it! **Cowsay** ships with few variations, called cow files, that can usually be found in **/usr/share/cowsay.** To see the cow file options available on your system, use **-l** flag after cowsay. Then, use the **-f **flag to try one out.

```
$ cowsay -f dragon "Run for cover, I feel a sneeze coming on."
_______________________________________
/ Run for cover, I feel a sneeze coming \
\ on. /
---------------------------------------
\ / \ //\
\ |\___/| / \// \\
/0 0 \__ / // | \ \
/ / \/_/ // | \ \
@_^_@'/ \/_ // | \ \
//_^_/ \/_ // | \ \
( //) | \/// | \ \
( / /) _|_ / ) // | \ _\
( // /) '/,_ _ _/ ( ; -. | _ _\.-~ .-~~~^-.
(( / / )) ,-{ _ `-.|.-~-. .~ `.
(( // / )) '/\ / ~-. _ .-~ .-~^-. \
(( /// )) `. { } / \ \
(( / )) .----~-.\ \-' .~ \ `. \^-.
///.----..> \ _ -~ `. ^-` ^-_
///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~
/.-~
```


My real beef with** cowsay** is that I don’t have enough time today to really milk the cow puns for all they are worth. The steaks are just too high, and I might butcher the joke.

On a more serious note, I had completely forgotten about **cowsay** until I re-encountered it when learning Ansible playbooks. If you happen to have **cowsay **installed, when you run a playbook, you’ll get your output from a series of cows. For example, running this playbook:

```
- hosts:
- localhost
tasks:
- action: ping
```


Might give you the following:

```
$ ansible-playbook playbook.yml
__________________
< PLAY [localhost] >
------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
________________________
< TASK [Gathering Facts] >
------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [localhost]
_____________
< TASK [ping] >
-------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [localhost]
____________
< PLAY RECAP >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
localhost : ok=2 changed=0 unreachable=0 failed=0
```


**Cowsay** is available under a GPLv3 license, and you can find the Perl [source code](https://github.com/tnalpgge/rank-amateur-cowsay) on GitHub. I’ve also seen versions floating around in other languages, so take a look around for other variants; here’s [one in R](https://github.com/sckott/cowsay), for example. Implementing your own version in your language of choice might even be a fun programming learning task.

Now that **cowsay** is out of the way, we can move on to greener pastures.

Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.

Check out yesterday's toy, [How to bring good fortune to your Linux terminal](https://opensource.com/article/18/12/linux-toy-fortune), and check back tomorrow for another!

## 4 Comments