9 really odd Linux commands

figlet shs
Credit: Sandra Henry-Stocker
RELATED TOPICS

You can probably make your Unix systems hum -- deliver great performance, withstand threats to file system integrity, resist hacker attacks, report problems, and run smoothly no matter what your users throw at them. But can you make them do goofy things? Let's look at a collection of some really oddball tools that you might never have heard of are tried.

shuf

The shuf command -- short for "shuffle" reorganizes the lines of a file in some pseudorandom way. Start out with a file listing the days of the week and you can rearrange them in any of 5,040 ways (7 * 6 * 5 * 4 * 3 * 2). Maybe more useful for determining who brings cookies into the office each day for the next couple of weeks.

$ shuf Days-of-Week
Monday
Tuesday
Wednesday
Saturday
Thursday
Sunday
Friday
$ shuf Days-of-Week
Sunday
Saturday
Wednesday
Tuesday
Thursday
Monday
Friday

You don't have to display the result of the entire shuffling either. Trying to decide who of your two dozen coworkers gets to bring in cookies for the rest of the week? No need to draw straws. Just limit the output to three of your shuf command with -n option like this.

$ shuf -n 3 staff
James
Kevin
May

You can also shuffle a range of numbers.

$ shuf -i 2-11
8
11
7
9
4
2
10
5
6
3

And you can have the command select just a handful of numbers out of a fairly large range.

$ shuf -n 5 -i 1-1000
85
952
149
498
2

rev

The rev command reverses lines whether passed to the command as standard in or stored in a file.

$ echo Hello, World! | rev
!dlroW ,olleH
$ rev Days-of-Week
yadnuS
yadnoM
yadseuT
yadsendeW
yadsruhT
yadirF
yadrutaS

tac

The tac command is sort of the reverse of the cat command. It displays the content of a file, but in reverse order. There are probably many times when doing this can be both handy and sensible, but the command still strikes me as odd.

$ tac Days-of-Week
Saturday
Friday
Thursday
Wednesday
Tuesday
Monday
Sunday

sl

And, if tac didn't go far enough, we also have the sl command to punish people who mistakenly type sl when they meant to type ls. Their punishment? A train (i.e., steam locomotive) drives across their screen.

                      (@@) (  ) (@)  ( )  @@    ()    @ 
                 (   )
             (@@@@)
          (    )

        (@@@)
       ====        ________                ___________
   _D _|  |_______/        \__I_I_____===__|_________|
    |(_)---  |   H\________/ |   |        =|___ ___|
    /     |  |   H  |  |     |   |         ||_| |_||
   |      |  |   H  |__--------------------| [___] |         
   | ________|___H__/__|_____/[][]~\_______|       |            
   |/ |   |-----------I_____I [][] []  D   |=======|__
 __/ =| o |=-~~\  /~~\  /~~\  /~~\ ____Y___________|__|
  |/-=|___|=    ||    ||    ||    |_____/~\___/
   \_/      \O=====O=====O=====O_/      \_/

look

The look command can be handy if you need to come up with words that start with a particular string. In the example below, we're looking for words that start with the string "fun".

$ look fun | head -11
fun
funambulant
funambulate
funambulated
funambulating
funambulation
funambulator
funambulatory
funambule
funambulic
funambulism

But look, it found me too. Hmmm.

$ look sandra
Sandra
sandra
Sandrakottos

The look command uses the words file (e.g., /usr/share/dict/words) on your system and only grabs words that start with the string you provide. A grep -i command would find a lot more matches in most cases.

yes

The yes command puts you into a loop that repeats the same string over and over again. It does have some useful purposes, though, even while this behavior might seem silly. People sometimes use it to provide as many "yes" responses as might be need to handle a demanding script.

The default behavior of yes is to provide an endless loop of "y" responses.

$ yes | head -4
y
y
y
y

You can, however, supply your own string.

$ yes Please loop forever | head -11
Please loop forever
Please loop forever
Please loop forever
Please loop forever
Please loop forever
Please loop forever
Please loop forever
Please loop forever
Please loop forever
Please loop forever
Please loop forever

cowsay

Probably one of the oddest commands that the powers behind Linux have come up with is the cowsay command that displays an ASCII cow saying whatever you want it to say. Here's an example. Note the use of the escape character to allow the display of the apostrophe.

$ cowsay I don\'t moo for just anyone
 _____________________________
< I don't moo for just anyone >
 -----------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

factor

Another unusual, though not really silly, command is the factor command that factors whatever number you provide. I just happened to try a number that has just two factors.

$ factor 33431
33431: 101 331

You can verify the result if you like using an expr command like this one.

$ expr 101 \* 331 33431

figlet

The last unusual command that I'm going to cover is called figlet. It uses a small number of enlarged keyboard characters to create banner text.

$ figlet Show me!
 ____  _                                    _
/ ___|| |__   _____      __  _ __ ___   ___| |
\___ \| '_ \ / _ \ \ /\ / / | '_ ` _ \ / _ \ |
 ___) | | | | (_) \ V  V /  | | | | | |  __/_|
|____/|_| |_|\___/ \_/\_/   |_| |_| |_|\___(_)

One of the most surprising thing about the figlet command is how many options are available. Someone put a lot of time into making sure that you could get the kind of output you want. Options include font variations, justification, character sets, etc. In the command below, we say to use a screen width of 40 and to center the output.

$ figlet -w 40 -c Can you do this?
   ____
  / ___|__ _ _ __    _   _  ___  _   _
 | |   / _` | '_ \  | | | |/ _ \| | | |
 | |__| (_| | | | | | |_| | (_) | |_| |
  \____\__,_|_| |_|  \__, |\___/ \__,_|
                     |___/
        _         _   _     _    ___
     __| | ___   | |_| |__ (_)__|__ \
    / _` |/ _ \  | __| '_ \| / __|/ /
   | (_| | (_) | | |_| | | | \__ \_|
    \__,_|\___/   \__|_| |_|_|___(_)

Here's an example where the input is taken from a file, a script font is used, and the screen width is controlled so that we don't have more than one day of the week per line -- output truncated.

$ figlet -f script -w 60 -p < Days-of-Week

  ()                   |
  /\         _  _    __|   __,
 /  \|   |  / |/ |  /  |  /  |  |   |
/(__/ \_/|_/  |  |_/\_/|_/\_/|_/ \_/|/
                                   /|
                                   \|
 ,__ __
/|  |  |                  |
 |  |  |   __   _  _    __|   __,
 |  |  |  /  \_/ |/ |  /  |  /  |  |   |
 |  |  |_/\__/   |  |_/\_/|_/\_/|_/ \_/|/
                                      /|
                                      \|

I've been told that figlet (launched as newban in Spring 1991) predates Linux by a number of months and is available on a wide variety of operating systems.

I hope that was fun.

This article is published as part of the IDG Contributor Network. Want to Join?

RELATED TOPICS
Lock down your servers more easily: A look inside the Microsoft Local Administrator Password Solution
View Comments
Join the discussion
Be the first to comment on this article. Our Commenting Policies