Comments on Linux shuf Command Tutorial for Beginners (with Examples)

If you ever played the game of cards, you'd likely be aware of the term shuffling. A bit hard to imagine, there's a Linux command line tool that exactly does that with lines in files. In this tutorial, we will discuss the basics of the 'shuf' command using some easy to understand examples.

6 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: phil

You can use the seq command to generate the sequence of number. seq 10 will generate the numbers 1 through 10 which you can pipe to shuf.

By: alex

Why would you even want to use simple numerical sequences as sample input for <code>shuf</code>, when there is the option -i to accomplish exactly that.

By: Pedro

Para GNU 8.26 no acaba de funcionar del todo bien,al realizar dentro de un bash#!/bin/bashvalor=$(shuf -ze -n6 {A..Z} {a..z} {1..9} )me escupe con el texto:AVISO: command substitution: ignored null byte in input.

**************************************************************

For GNU 8.26 it doesn't quite work quite right, when performing within a bash

#!/bin/bash

value = $ (shuf -ze -n6 {A..Z} {a..z} {1..9})

spits me out with the text:

WARNING: command substitution: ignored null byte in input.

 

 

By: alex

Remove the -z option from the command to get rid of the warning.

By: Alex

Just to be sure: does shuf -n 1 file have the same effect as shuf file | head -1 ? It's hard to check empirically ;-)

By: alex

Yes, the output from these two commands will be the same.