Random quotes and creatures using fortune and cowsay in Linux terminal

Option 2. Random fortune and cowsay for all users

To add random fortune and cowsay for a all users, you need to edit /etc/bash.bashrc file

vi /etc/bash.bashrc

Now add the following line at the bottom of the file:

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

Save and exit.

Reopen terminal and you will see a random creature quoting a different phrase/jokes for all users globally.

Little explanation about the code above

This code snippet is better as it checks whether cowsay and fortune exists in your system. So Line 1 does that…

    if [ -x /usr/games/cowsay -a -x /usr/games/fortune ]; then

Line 2 uses fortune and then pipes the quote to cowsay. But default cowsay would only use a cow to say the quote. We are using random creatures here using shuf -n1 to rotate files in /usr/share/cowsay/cows/ folder.

        fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1)

And of course Line 3 is end of the loop.

    fi

The outcome

So how does it look like at the end? Here’s few screenshots:

Random quotes and creatures using Fortune and Cowsay in Linux terminal - blackMORE Ops -5
A chicken (well I didn’t wanted to write the actual filename here!) talking intelligently instead of crossing the street.

 

Random quotes and creatures using Fortune and Cowsay in Linux terminal - blackMORE Ops -6
I am definitely going to avoid gunfire in bathroom tonight.

And of course for me as a Kali Linux user, Dragon!!

Random quotes and creatures using Fortune and Cowsay in Linux terminal - blackMORE Ops -7
Dragon FTW

Hope you find this little guide useful. Enjoy and don’t forget to share.

 

Check Also

A .vimrc config file everyone should use

Ever had that issue when you login to a Linux terminal, editing a file and …

mRemoteNG - blackMORE Ops

PuTTY alternatives

PuTTY is the most popular SSH client for Windows based systems. In fact it’s so …

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!

Leave your solution or comment to help others.

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

Discover more from blackMORE Ops

Subscribe now to keep reading and get access to the full archive.

Continue reading

Privacy Policy on Cookies Usage

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