Here’s a script that uses GNU sort’s random option:
ls |sort -R |tail -$N |while read file; do
# Something involving $file, or you can leave
# off the while to just get the filenames
done
More Related Contents:
- How to generate random number in Bash?
- Select random lines from a file
- Input data to a shell script [closed]
- How to escape single quotes within single quoted strings
- How can I add numbers in a Bash script?
- Batch equivalent of Bash backticks
- How to find the difference in days between two dates?
- Running script upon login in mac OS X [closed]
- How to append output to the end of a text file
- Command substitution: backticks or dollar sign / paren enclosed? [duplicate]
- Why does my Bash counter reset after while loop
- How do I use a file grep comparison inside a bash if/else statement?
- Set a parent shell’s variable from a subshell
- Value too great for base (error token is “08”) [duplicate]
- How to do a logical OR operation for integer comparison in shell scripting?
- What expands to all files in current directory recursively?
- Looping through all files in a directory [duplicate]
- I can’t seem to use the Bash “-c” option with arguments after the “-c” option string
- Assign string containing null-character (\0) to a variable in Bash
- How do I limit the running time of a BASH script
- Execute command containing quotes from shell variable [duplicate]
- Why equal to operator does not work if it is not surrounded by space?
- Syntax for a single-line while loop in Bash
- In bash, is there an equivalent of die “error msg”
- How to zero pad numbers in file names in Bash?
- Use GNU find to show only the leaf directories
- Get the name of the caller script in bash script
- How does testing if a string is ‘greater’ than another work in Bash?
- What is the shortest way to get n-th column of an output?
- Can bash script be written inside a AWS Lambda function