Tuesday, 29 October, 2019 UTC


Summary

The command-line is extremely powerful. Depending on your setup, it may not be much to look at though. Light text on a dark background, dark text on a light background, it’s still just text. Text can get boring to look at all the time, even if your terminal supports colors in all their 256 shades of glory. In the spirit of Halloween, I thought it would be fun to discuss how we can “dress up” command-line output by using the cowsay command.
cowsay is a command that can either receive a string, or can have output from another command piped to it. It then takes the text input and prints it out in a ASCII art speech bubble that is being said by a, you guessed it, an ASCII art cow.
Anybody else getting those nostalgia feels?
Getting Started
Unfortunately, the cowsay command is not standard issue and will need to be installed on your system. Even though it’s not mission critical piece of software, it’s been around long enough that it’s not hard to find in your favorite package manager.

Alligator.io recommends ⤵

👉 Learn Node, a video course by Wes Bos
You'll learn things like user auth, database storage, building a REST API and uploading images in Node.js by building a real world restaurant application.
ⓘ About this affiliate link
Cow Say What?
Using the cowsay command is quite simple. The easiest way to go about it is to pass in a string you’d like to have echoed back to you:
$ cowsay 'Alligators are better than cows' _________________________________ < Alligators are better than cows > --------------------------------- \  ^__^ \  (oo)\_______ (__)\  )\/\ ||----w | || || 
You can also pipe the output from another command into cowsay:
$ ls -al /tmp | cowsay -n __________________________________________________________________________ / total 16K \ | drwxrwxrwt 20 root root 500 Oct 28 18:27 ./ | | drwxr-xr-x 17 root root 4.0K Oct 7 23:34 ../ | | drwxr-xr-x 3 josh josh 80 Oct 28 18:45 checkup-db-josh/ | | -rw------- 1 josh josh 415 Oct 28 10:07 dropbox-antifreeze-Tn4c0m | | -rw------- 1 josh josh 575 Oct 28 10:07 dropbox-antifreeze-XEGBYQ | | drwxrwxrwt 2 root root 40 Oct 28 10:07 .font-unix/ | | drwxrwxrwt 2 root root 60 Oct 28 10:07 .ICE-unix/ | | drwx------ 2 josh josh 40 Oct 28 10:08 net-export/ | | drwxr-xr-x 3 josh josh 60 Oct 28 10:19 npm-5264-7067ddca/ | | drwx------ 2 josh josh 60 Oct 28 18:27 nvimGvMCTk/ | | drwx------ 2 josh josh 80 Oct 28 10:08 .org.chromium.Chromium.qZNfp0/ | | drwx------ 2 josh josh 80 Oct 28 11:40 .org.chromium.Chromium.zTmUVs/ | | drwx------ 2 josh josh 40 Oct 28 10:08 Slack Crashes/ | | drwxrwxrwt 2 root root 40 Oct 28 10:07 .Test-unix/ | | drwx------ 2 josh josh 40 Oct 28 14:02 tracker-extract-files.1000/ | | -r--r--r-- 1 gdm gdm 11 Oct 28 10:07 .X1024-lock | | drwxrwxrwt 2 root root 80 Oct 28 10:07 .X11-unix/ | \ drwxrwxrwt 2 root root 40 Oct 28 10:07 .XIM-unix/ / -------------------------------------------------------------------------- \  ^__^ \  (oo)\_______ (__)\  )\/\ ||----w | || || 
The -n helps to deal with input strings that have line breaks, else cowsay will end up just smashing the string all together.
Absolutely no judgement if you want to alias ls and other commands to always pipe to cowsay. I’d be lying if I said I hadn’t done it before myself.
Thinking Cow
I get it, being so forward about how much better alligators are than cows could potentially land you in a fight. That’s okay though, the cowsay package also comes with a slightly more subtle “thinking” version.
When you use cowthink, the speech bubble is replaced with a thought bubble, so you can keep those thoughts in your head:
$ cowthink Alligators are better than cows _________________________________ ( Alligators are better than cows ) --------------------------------- o ^__^ o (oo)\_______ (__)\  )\/\ ||----w | || || 
Way to play it cool, my friend.
Tux and friends
cowsay and cowthink aren’t just limited to an extremely accurate looking ASCII cow, it actually comes with a whole slew of characters to choose from.
To list out which ones you available available, pass in the -l argument:
$ cowsay -l Cow files in /usr/share/cows: beavis.zen blowfish bong bud-frogs bunny cheese cower daemon default dragon dragon-and-cow elephant elephant-in-snake eyes flaming-sheep ghostbusters head-in hellokitty kiss kitty koala kosh luke-koala meow milk moofasa moose mutilated ren satanic sheep skeleton small sodomized stegosaurus stimpy supermilker surgery telebears three-eyes turkey turtle tux udder vader vader-koala www 
YMMV on how SFW some of these are. To tell cowsay which one to use, pass in the -f argument followed by the name of the character:
$ cowsay -f tux 'Alligators rock more than Linux!' __________________________________ < Alligators rock more than Linux! > ---------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/ $ cowsay -f skeleton 'Sorry Linus' _____________ < Sorry Linus > ------------- \ (__) \ /oo| \ (_"_)*+++++++++* //I#\\\\\\\\I\ I[I|I|||||I I ` I`I'///'' I I I I I I ~ ~ ~ ~ Scowleton 
Sorry Linus, indeed.
Equestria Fun
One of the best parts of Open Source software is that silly little programs like cowsay can inspire developers to build even better products. One such example is ponysay.
ponysay is just as it sounds, a reimplementation of cowsay but with ponies:
And it’s glorious!