Linux shuf Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux shuf Guide
Complete beginner-friendly guide to shuf on Linux, covering Arch Linux, CachyOS, and other distributions including random shuffling, random selection, and randomization.
Table of Contents
shuf Basics
Shuffle Lines
Basic usage:
# Shuffle lines
shuf file.txt
# Randomly shuffles lines
Random Numbers
Number range:
# Random numbers
shuf -i 1-10
# -i = input range
# Output: random order of 1-10
Shuffling Lines
File Shuffle
Shuffle file:
# Shuffle file lines
shuf file.txt
# Randomly reorders lines
Multiple Lines
Shuffle input:
# Shuffle input
echo -e "line1\nline2\nline3" | shuf
# Shuffles input lines
Random Selection
Select N Lines
Random selection:
# Select random lines
shuf -n 5 file.txt
# -n = number (selects 5 random lines)
One Random Line
Single line:
# One random line
shuf -n 1 file.txt
# Selects one random line
Input Sources
From Range
Number range:
# From range
shuf -i 1-100
# Shuffles numbers 1-100
From File
File input:
# From file
shuf file.txt
# Shuffles lines from file
Troubleshooting
shuf Not Found
Check installation:
# shuf is part of coreutils
# Usually pre-installed
# Check shuf
which shuf
Summary
This guide covered shuf usage, random shuffling, and random selection for Arch Linux, CachyOS, and other distributions.
Next Steps
- sort Guide - Sorting data
- Bash Scripting Guide - Scripting basics
- shuf Documentation:
man shuf
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.