tags:

views:

1939

answers:

3

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
No need to take $RANDOM modulo 1000; just use $RANDOM---with $RANDOM modulo 1000 there will definitely be duplicates with 2000 files.
Norman Ramsey
I told him it wasn't mine, it's something he could use as a starting point. =)
EdgarVerona
+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
Cool, didn't know sort -R; I used bogosort previously :-p
alex
A: 

wow cool thanks a lot.

lin