January 28, 2014 · cal console cowsay debian figlet fortune hacks linux script shell sl tricks

Funny And Useless Linux Command

It can never be said enough: the terminal is a very powerful tool, and is probably the most interesting part of Unix systems. Among the vastness of useful commands and scripts that you can use and make your work easier, some seem to be less practical, if not completely useless. I've selected a couple of commands that are useless because they are quite funny, yet not funny because they are useless (or maybe the other way around?). If you are searching for ASCII art, random math curiosities, or various (in)utilities, this is the best of the useless. This post is based on Debian commands. If you use another distro, please adjust your commands appropriately.

cal| time cat | sl | rev | factor | multiplication tables | Pi | Figlet | cowsay | fortune | combos

cal

Few people know this, but any Unix system comes with a built-in calendar. To access it, you can simply type:

bubbl@hades ~ % cal 
    January 2014      
Su Mo Tu We Th Fr Sa  
          1  2  3  4  
 5  6  7  8  9 10 11  
12 13 14 15 16 17 18  
19 20 21 22 23 24 25  
26 27 28 29 30 31

This will display the current month. However, you can select the precise year and month that you want as an argument. And, to be fully useless, the option -j displays Julian days (the number of days from January 1st). To sum up:

Usage: 
cal [general options] [-hjy] [[month] year] 
cal [general options] [-hj] [-m month] [year] 
ncal [general options] [-bhJjpwySM] [-s country_code] [[month] year] 
ncal [general options] [-bhJeoSM] [year] 
General options: [-NC31] [-A months] [-B months] 
For debug the highlighting: [-H yyyy-mm-dd] [-d yyyy-mm]

[TOP]

time cat

You can use this command as a built-in timer. It will run in the background until you stop it, and will then report the time elapsed between the start and the end of its process. As useful as it may seems, it is actually quite unpractical because you cannot check its value unless you stop it. I suppose it can become handy in a very specific situation but I have trouble imagining which one exactly. To launch it, just type:

time cat

kill it with [Ctrl]+C, you will get something like this:

$ time cat 
^C 
real 0m9.928s user 0m0.000s sys 0m0.000s

[TOP]

sl

One of the most common mistakes is typing sl instead of ls command. sl is a joke software or classic UNIX game. It is a steam locomotive runs across your screen if you type "sl" (Steam Locomotive) instead of "ls" by mistake:

sl

Steam Locomotive isn't installed by default, so you'd have to add it on your own with:

sudo apt-get install sl

Invoke it with

sl

in your terminal and enjoy a train steaming through your screen. It also supports the following options:

- -a : An accident seems to happen. You'll feel pity for people who cry for help.
- -l : shows little one.
- -F : It flies.
- -e : Allow interrupt by Ctrl+C.

[TOP]

rev

This command is for reversing any input (as its name suggests). When I say reverse, it means that if the input is "Linux", the output will be "xuniL". Type

rev

in your terminal window and you will enter an interactive mode:

$ rev 
Linux 
xuniL 
Debian 
naibeD 
Radar 
radaR

Quit by using [Ctrl]+C. rev also works to reverse an entire file:

$ rev test.txt 
.im mudretni lev ibroM .tile sitanenev ,ca siruam mudnebib ,susruc ucra ni ecsuF .mutnemref siuq siprut atrop taptulov sullesahP .maid eranro lev euqsetnelleP .taptulov tare mauqilA .mulubitsev allignirf isin a tse silucai nI .sum sulucidir rutecsan ,setnom tneirutrap sid singam te subitanep euqotan siicos muC .missingid etatupluv sullet des icro murtur maN .tile gnicsipida rutetcesnoc ,tema tis rolod muspi meroL

[TOP]

factor

Time to do some maths. Let's begin easy with the command <strong>factor</strong> which can decompose a given number into prime factors:

$ factor 3214325237489324 
3214325237489324: 2 2 7 7 23 61 86111 135743

As a side note, prime numbers and the decomposition into prime factors is actually the basis for modern cryptography and Internet security. Knowing a little bit about them is always interesting. If you want to learn more, take a look at the RSA encryption.

[TOP]

Multiplication Tables

This is actually more of a script than a command but it is impossible to ignore it when talking about funny stuff you can do in a console:

for i in {1..9}; do 
  for j in $(seq 1 $i); do 
    echo -ne $i×$j=$((i*j))\\t;
  done 
  echo
done 

The terminal will display the multiplication table, nicely ordered in columns. Incredibly useless, and pretty long to remember, but you have to admit that it looks good.

[TOP]

Pi

A bit more complex, you can calculate an approximation of pi through commands using

$ seq -f '4/%g' 1 2 99999 | paste -sd-+ | bc -l

This combination of commands is a little bit harder to understand, but if you really want to know, seqgenerates the sequence of 4/1, 4/3, 4/4 until 4/99999 (without 4/2), paste merges these lines using a delimiter, and bc does the final approximation using a math library.

[TOP]

Figlet

Figlet is a command for those who love to write in ASCII art. It greatly simplifies this task as it automatically transforms any given string. It comes with a bunch of fonts, by default at /usr/share/figlet/fonts/, and you can of course add yours. You must install figlet if you want to use it:

sudo apt-get install figlet

Use it with:

figlet [-f path to the font] [string]

For example:

figlet -f smmono12.tlf Linux 

â–—â––     â–ˆ                 
▐▌     ▀                 
▐▌    ██  ▐▙██▖▐▌ ▐▌▝█ █▘
▐▌     █  ▐▛ ▐▌▐▌ ▐▌ ▐█▌ 
▐▌     █  ▐▌ ▐▌▐▌ ▐▌ ▗█▖ 
▐▙▄▄▖▗▄█▄▖▐▌ ▐▌▐▙▄█▌ ▟▀▙ 
▝▀▀▀▘▝▀▀▀▘▝▘ ▝▘ ▀▀▝▘▝▀ ▀▘

More examples on how to incorporate figlet into a more useful usage, can be found on Mewbies.

[TOP]

cowsay

cosway is very famous in the Linux world, but this command is not always present by default in every distribution. Install it with the command:

sudo apt-get install cowsay

It displays a cow in ASCII art saying whatever string you want. It comes with a couple of other characters and you can add your own. The default directory for them is /usr/share/cows/. The syntax is:

cowsay [-f path of another character] [string for the cow]

For example:

cowsay -f gnu Linux is cool
 _______________
&lt; Linux is cool &gt;
 ---------------
    \               ,-----._
  .  \         .  ,'        `-.__,------._
 //   \      __\\'                        `-.
((    _____-'___))                           |
 `:='/     (alf_/                            |
 `.=|      |='                               |
    |)   O |                                  \
    |      |                               /\  \
    |     /                          .    /  \  \
    |    .-..__            ___   .--' \  |\   \  |
   |o o  |     ``--.___.  /   `-'      \  \\   \ |
    `--''        '  .' / /             |  | |   | \
                 |  | / /              |  | |   mmm
                 |  ||  |              | /| |
                 ( .' \ \              || | |
                 | |   \ \            // / /
                 | |    \ \          || |_|
                /  |    |_/         /_|
               /__/

More examples on how to incorporate cowsay into a more useful usage, can be found on Mewbies.

[TOP]

fortune

fortune displays a random sentence, in the same spirit as fortune cookies. It is not always installed by default so you may want to add it:

sudo apt-get install fortune

It comes with a very handy option: -s (for short), which will limit to fortunes composed of one sentence or less.

fortune [-s]
$ fortune 
BOO! We changed Coke again! BLEAH! BLEAH!

More examples on how to incorporate fortune into a more useful usage, can be found on Mewbies.

[TOP]

Combos

The fun part is now to combine the previous commands for a funnier result. A famous combination is fortune and cowsay, which creates a cow in ASCII art telling you a random fortune:

fortune -s | cowsay -f duck
 _________________________________________
/ The truth of a thing is the feel of it, \
| not the think of it.                    |
|                                         |
\ -- Stanley Kubrick                      /
 -----------------------------------------
 \
  \
   \ <()_
      (__)__ _

Using simple oneliners, you can make cows display just anything, even creating cool MOTD screens, from simple ASCII to simething like:

cowsay 'Hello $USER. Server's time &amp; uptime is $(uptime)' 
 -------------------------------------------
/ Hello bubbl. Server's time &amp; uptime is \
| 13:51:42 up 3:48, 3 users, load        |
\ average: 2.28, 2.47, 2.40              /
 ----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Again, for more examples head to Mewbies and enjoy!

[TOP]

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket

Contact