I have a directory with 2000 files or so. I want a script or a list of piped commands that will allow me to select a random sample of N files.
+5
A:
Does this work? I don't use Bash, but a quick Google search gave me this link:
http://benjisimon.blogspot.com/2008/05/bash-shell-hack-picking-random-set-of.html
EdgarVerona
2009-01-05 19:18:41
No need to take $RANDOM modulo 1000; just use $RANDOM---with $RANDOM modulo 1000 there will definitely be duplicates with 2000 files.
Norman Ramsey
2009-01-05 19:23:44
I told him it wasn't mine, it's something he could use as a starting point. =)
EdgarVerona
2009-01-05 20:11:58
+4
A:
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
jleedev
2009-01-05 20:01:13