Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wish to display a cowsay message in every terminal window. The command I use is

 fortune | cowsay

Any ideas how to make it appear whenever I start a new terminal session?

share|improve this question
up vote 26 down vote accepted
  • Open the file ~/.bashrc (or /etc/bash.bashrc if it should work globally for all users).

  • Add the following at the bottom of the file:

    if [ -x /usr/games/cowsay -a -x /usr/games/fortune ]; then
        fortune | cowsay
share|improve this answer
does the -x flag mean "if exists" ? – theTuxRacer Dec 6 '10 at 16:58
Yes, "-x" tests if that file exists and is executable. For more information on the the test program see its man page: man test ([ ... ] is short for test ...). – htorque Dec 6 '10 at 17:03

BONUS: If you're using bash you can make a ~/.bash_logout file and it will execute that when you log out. Make sure to have it sleep for a second or so, or you'll never see it.

cowsay "See you later"; sleep 1

share|improve this answer
wow, thats neat! Ill do it immediately! – theTuxRacer Jan 24 '11 at 7:54

I would consider setting a limit to the size of the fortune command requested.

fortune -s | cowsay

This will produce at most 160 characters. This is a good size for a greeting, anything more than that and long fortunes will flood your terminal.

share|improve this answer

I use

fortune | cowsay -f `ls -1 /usr/share/cowsay/cows/ | sort -R | head -1` -n

This will display a random fortune using a random 'cow'. There's probably a better way to get a random 'cow', but this works for me just fine.

share|improve this answer

Better you use .bash_profile because .bashrc is also executed at commands like scp and they will fail silently if there is any output

I found a nice script on pastebin. currently using it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.