shuf Command Cheat Sheet
Basic Usage
Generate a random permutation of the lines in a file
echo -e "line1\nline2\nline3" | shuf
Specify Number of Output Lines
Generate a random permutation of three lines in a file
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
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
(head -n 1 file.csv && tail -n +2 file.csv | shuf) > shuffled_file.csv