Skip to content

Linux: Fun Time

The terminal does not have to be all work and no play. Here are some fun tricks and commands to break up the routine and make your command line experience a little more enjoyable. None of these are required for the course, but they are a great way to get comfortable with the terminal and discover that it has a personality of its own.

One-Liners

Do you love Linux?

yes "I love Linux!"
# Stop it with [Ctrl] + [C]

Roll a dice:

shuf -i 1-6 -n 1

Prime factors of the numbers 10, 50, and 100:

factor 10 50 100

Progress bar:

echo "Some long task in progress..." | pv -qL 5

Reverse the order of characters in a string:

echo "123456789" | rev
echo "a man, a plan, a canal, panama" | tr -d '[:punct:]' | tr -d ' ' | rev

Reverse complement a DNA sequence:

echo "ATGCAT" | rev | tr 'ATGC' 'TACG'

Tick .. Tick

Print the current time every 3 seconds in an infinite loop.

while true; do echo "$(date '+%T')"; sleep 3; done
# Stop it with [Ctrl] + [C]

Count Down

for i in {60..1}; do echo "$i seconds remaining"; sleep 1; done; echo "Time is up"

A Place by the Fire

aafire

Weather Check

curl wttr.in/zurich

Info

There are several cities named Zurich worldwide, including one in Rooks County, Kansas. If you do not specify a country, you might see the weather for a different Zurich depending on your location.

Steam Engine

Everyone knows ls lists files, but have you tried sl?

sl

What Is the Cow Saying?

cowsay generates ASCII art of a cow with your message in a speech bubble.

# Give a direct message to the cow
cowsay "Hello there!"

# Make the cow say text from a file
echo "tfjzf uif npp-nfou!" | tr 'b-x' 'a-y' > moo.txt
cowsay `cat moo.txt`

# Customise the cow
ls | cowsay -f tux  # Meet your tuxedo cow

# Get a fortune from a cow
clear ; fortune | cowsay -f eyes

# See all the different cows available
for i in $(cowsay -l); do cowsay -f $i "$i"; done

Sources: cowsay on GitHub and Wikipedia

Snake Game

nsnake