shuf
Learn how to use the shuf command in Linux to generate random permutations, numbers, and shuffle data efficiently
Basic Usage
Generate a random permutation of the lines in a file
Generate a random permutation of the lines from standard input
echo -e "line1\nline2\nline3" | shuf
Specify Number of Output Lines
Generate a random permutation of three lines in a file
Generate a single random line from standard input
echo -e "line1\nline2\nline3" | shuf -n 1
Generating Random Numbers
Generate a random number between 1 and 10
Generate three random numbers between 1 and 100
Repeat Output Lines
Generate 10 random numbers between 1 and 5 with repetition
Zero-Padded Numbers
Generate a random, zero-padded number between 1 and 100
Generate three random, zero-padded numbers between 1 and 1000
Using shuf With Other Commands
Shuffle the lines of the /etc/passwd file
List files in random order
Pick a random file from a directory
Display random log lines
cat /var/log/syslog | shuf -n 10
Shuffle CSV data but keep header line
(head -n 1 file.csv && tail -n +2 file.csv | shuf) > shuffled_file.csv