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.
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
cards.txt. This file is ordered by suit and number.
shuf cards.txt 4D 9D QC 3S 6D
shuf command shuffles the lines and outputs this to standard output.
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 KH
To select more than one line change the number.
shuf -n 5 cards.txt 4H 9S KH 9D 9H
To shuffle words passed to
shuf in standard input use the
-e option. This shuffles items separated by spaces.
shuf -e one two three three two one
If you wanted to quickly decide whose turn it is to make the tea you can use
shuf -n 1 -e George Kirsten Fin Bea Bea
Bea make the tea!
Have an update or suggestion for this article? You can edit it here and send me a pull request.
Vim: So long Pathogen, hello native package loading
Vim 8 added a native way to load third-party packages. This means, for me at least, there is no longer any need to use a third party plugin helper like Pathogen.
Linux and Unix more command tutorial with examples
Tutorial on using more, a UNIX and Linux command for viewing the contents of a file or files one screen at a time. Examples of viewing a file, viewing multiple files, searching using regular expressions and opening the file in a text editor.
Vim: you don't need NERDtree or (maybe) netrw
Vim's netrw file browser is good enough. With a few tweaks there is no need for plugin like NERDtree. For many tasks you may not even need netrw.