I’m Nishal. I came to Hamon as a UI/UX designer. At Hamon my first project was Lycaeum. Since then I have been handling the UI/UX work for Lycaeum. As a part of Lycaeum project expansion I got this wonderful opportunity to attend the mentoring class of Noufal Sir. This was totally a new experience for me. This is a five months course. For that he gave us a monthly activity calendar.

Daily we have to practise Gtypist in the shell, practise programming and read Technical and Non-technical books which he suggested.

Every Monday a five minutes presentation on a topic assigned to each of us.

Blogging on Sundays.

We have to tick daily activity progress. This changed me a lot. After seeing all the ticks, my confidence level has increased significantly.

Here I am going to explain about the presentation topic I was assigned to last Monday. Each of the attendees got a different command used in UNIX programming. I got the command shuf.

What is the shuf command in UNIX?

The shuf command generates random permutations from input lines to standard output. If given a file or series of files it will shuffle the lines and write the result to standard output. It can also limit the number of results returned supporting selecting random lines from a file or data from a list.

How to shuffle the contents of a file

To shuffle the lines in a file using the shuf command pass a file, files or standard input to the command. The result will be printed to standard output. In the following example we have a list of cards in a file saved as poem.txt This file is ordered by suit and number.

cat poem.txt
Water,water,every where,
And all the boards did shriks;
Water, water, every where,
Nor any drop to drink
shuf poem.txt
Nor any drop to drink
Water,water,every where,
And all the boards did shriks;
Water, water, every where,

The shuf command shuffles the lines and outputs this to standard output.

How to pick a random line from a file

To pick a random line from a file using shuf use the -n option. This limits the output to the number specified.

shuf -n 1 cards.txt

To select more than one line change the number.

shuf -n 5 cards.txt

How to shuffle standard input

To shuffle words passed to shuf in standard input use the -e option. This shuffles items separated by spaces.

shuf -e one two three

If you wanted to quickly decide whose turn it is to make the tea you can use shuf.

shuf -n 1 -e Muhammed Nishal Bea

Bea make the tea!