Home / Command Line Interface (CLI) / Random quotes and creatures using fortune and cowsay in Linux terminal

Random quotes and creatures using fortune and cowsay in Linux terminal

fortune is a simple program that displays a pseudorandom message from a database of quotations that first appeared in Version 7 Unix. Random quotes and creatures using Fortune and Cowsay in Linux terminal - blackMORE OpsThe most common version on modern systems is the BSD fortune, originally written by Ken Arnold. Distributions of fortune are usually bundled with a collection of themed files, containing sayings like those found on fortune cookies (hence the name), quotations from famous people, jokes, or poetry.

cowsay is a program which generates ASCII pictures of a cow with a message. It can also generate pictures using pre-made images of other animals, such as Tux the Penguin, the Linux mascot. Tony Monroe is credited as the original author. Since it is written in Perl, it is adaptable to other systems such as Microsoft Windows. .cow files for cowsay exist which are able to produce different variants of “cows”, with different kinds of “eyes”, and so forth. It is sometimes used on IRC, desktop screenshots, and in software documentation. It is more or less a joke within hacker culture, but has been around long enough that its use is rather widespread. In 2007 it was highlighted as a Debian package of the day.

Fortune and Cowsay – random quotes and animals

Normally all the guides using fortune and cowsay uses the default creatures (a.k.a Cow!) to show different quotes. There’s plenty of guides on that. However, I wanted to show a random creature saying different fortune quotes on my terminal.I could find random figment of instructions in different forums and decided to write a small guide on how to do it properly. Few lines of codes, and my Linux terminal becomes more alive!

If you’re not familiar with fortune and cowsay then keep reading for details otherwise you can just jump into the code section.

Install Fortune

You can install fortune in Debian, Ubuntu or Kali Linux or any aptitude/apt-get based distro using the following command:

apt-get install fortune
(or)
sudo apt-get install fortune

Usually fortune is available in all the basic standard repositories, otherwise just add them for your respective Linux version.

You can install fortune in Redhat, CentOS, Fedora of any yum based Linux distros using the following command:

yum install fortune
(or)
sudo yum install fortune

If you have a different distro, the command is pretty much the same.

Once installed you can just type in fortune in your terminal and you get a random quote or joke.

Random quotes and creatures using Fortune and Cowsay in Linux terminal - blackMORE Ops -1

List and location of fortune files

Fortune quotes and files are located here:

ls -l /usr/share/games/fortunes/

Random quotes and creatures using Fortune and Cowsay in Linux terminal - blackMORE Ops -3

Check Also

How to get Public IP from Linux Terminal - blackMORE Ops

How to get Public IP from Linux Terminal?

Public addresses are assigned by InterNIC and consist of class-based network IDs or blocks of …

Z commands - View compressed files without uncompressing - blackMORE Ops

View compressed .gz files without uncompressing using Z commands in Linux

How often you bumped into a .gz file where you need to check the contents? …

14 comments

  1. BMO if you had a Like button. I would put like on everything I reed so far! Thanks for sharing knowledge, it’s Very usefull for begginers as me :)

  2. This script as written does not work on openSuse or Manjaro (based on Arch Linux) for two reasons:
    1. The binaries for cowsay and fortune are not in /usr/games but in /usr/bin.
    2. The data files for cowsay are not in /usr/share/cowsay/cows, but in /usr/share/cows.
    So the script has to be changed:

    if [ -x /usr/bin/cowsay -a -x /usr/bin/fortune ]; then
    fortune | cowsay -f $(ls /usr/share/cows/ | shuf -n1)
    fi

    • Thank you. I’ve only added Debian and Redhat based commands here. I’ll update the post with your comments soon.

    • You can also add this on your “$HOME/.bash_aliases”, which should be called from your “$HOME/.bashrc”. As long as you path is setup, it should execute independent of file location:

      if [[ $(which cowsay > /dev/null) -eq 0 ]] && [[ $(which fortune > /dev/null) -eq 0 ]] ; then
      cowsay -f $(ls $(cowsay -l | awk ‘NR==1 {print $4}’ | sed ‘s/://’) | shuf -n1) $(fortune)
      fi

      And you can also play with COWPATH if you want to do it in a different way.

      • Correcting my code:

        if [[ $(which cowsay > /dev/null ; echo $?) -eq 0 ]] && [[ $(which fortune > /dev/null ; echo $?) -eq 0 ]] ; then
        cowsay -f $(ls $(cowsay -l | awk ‘NR==1 {print $4}’ | sed ‘s/://’) | shuf -n1) $(fortune)
        echo
        fi

  3. BMO, I have this question, I’ve been a windows user for many years, and is quite awkwarding to work on a OS whitout antivirus and firewall! Feels like driving whithout seatbelt (pass the expression!) I’ve tryied clamav and fgwc firewall on ubuntu but seem to not work on Kali! What’s your opinion about antivirus and firewalls for kali? Do you have any? how do you have your protect system setup?

  4. Hmm… Interesting…!!! Thanx for Sharing man..!
    Currently i am generating Random Quotes on my terminal by editing .bashrc.. it looks someting like this…

    # To extract ones digit of second from system clock

    #a=`date|cut -c 19`
    a=`date|cut -c 18-19`
    a=$((${a#0}%16))

    # Array containing quotes- you can edit it to your favorite quotes

    var=(” Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better.

    \n \t\t\t\t\t\t\t-Samuel Beckett ” “Never give up, for that is just the place and time that the tide will turn.

    \n \t\t\t\t\t\t\t-Harriet Beecher Stowe ” “Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.

    \n \t\t\t\t\t\t\t-Thomas A. Edison” “Life isn’t about getting and having, it’s about giving and being.

    \n \t\t\t\t\t\t\t-Kevin Kruse” “You may be disappointed if you fail, but you are doomed if you don’t try.

    \n \t\t\t\t\t\t\t-Beverly Sills” “Strive not to be a success, but rather to be of value.

    \n \t\t\t\t\t\t\t-Albert Einstein” “Good or Evil is irrelevant, it’s the best story that wins!

    \n \t\t\t\t\t\t\t- El_Diablo ” “Real integrity is doing the right thing, knowing that nobody’s going to know whether you did it or not.

    \n \t\t\t\t\t\t\t-Oprah Winfrey” “You miss 100% of the shots you don’t take.

    \n \t\t\t\t\t\t\t-Wayne Gretzky” “Truth is more of a stranger than fiction.

    \n \t\t\t\t\t\t\t-Mark Twain” “People who are unable to motivate themselves must be content with mediocrity, no matter how impressive their other talents.

    \n \t\t\t\t\t\t\t-Andrew Carnegie” “Creativity comes from trust. Trust your instincts.

    \n \t\t\t\t\t\t\t-Rita Mae Brown” “Only those who dare to fail greatly can ever achieve greatly.

    \n \t\t\t\t\t\t\t-Robert F. Kennedy” “All our dreams can come true, if we have the courage to pursue them.

    \n \t\t\t\t\t\t\t-Walt Disney ” “Success consists of going from failure to failure without loss of enthusiasm.

    \n \t\t\t\t\t\t\t-Winston Churchill” “For certain is death for the born,
    And certain is birth for the dead;
    Therefore over the inevitable
    Thou shouldst not grieve.

    \n \t\t\t\t\t\t\t-Bhagavad Gita”)

    # Welcome message ! Edit it with your name

    cuscol=’\e[0;37m’
    NC=’\e[0m’ # No Color
    echo -e “——————————————————————————–”
    echo “**************** Welcome back El Diablo! *****************”

    echo -e “${cuscol}\n${var[$a]}${NC}”

    echo -e “——————————————————————————–”

    ################################################################

    i was looking for something like what u shared.. generating those creatures and all…..
    again thanx for sharing… i found what i wanted…. time for me to move on.. :D

  5. Is there a tutorial out there to make additionalascii art and then convert those to .cow files?

  6. can you do this on a mac command line?

  7. On Debian 8 this works:
    cowsay -f /usr/share/cowsay/cows/$(ls /usr/share/cowsay/cows | sort -R |head -1) “$(fortune )”

  8. root@localhost:~# cowsay
    bash: cowsay: command not found

  9. What’s up,I read your blogs named “Random quotes and creatures using fortune and cowsay in Linux terminal – blackMORE Ops” on a regular basis.Your story-telling style is witty, keep doing what you’re doing! And you can look our website about proxy list.

  10. What i do not understood is in reality how you
    are no longer actually a lot more well-favored than you might be right now.
    You are very intelligent. You know thus considerably on the subject of this matter,
    produced me individually consider it from so many varied angles.
    Its like men and women don’t seem to be interested except it’s something to accomplish with Lady gaga!
    Your personal stuffs outstanding. At all times
    handle it up!

Use WordPress.com, Twitter, Facebook, or Google+ accounts to comment (anonymous comments allowed)

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Privacy Policy on Cookies Usage

Some services used in this site uses cookies to tailor user experience or to show ads.