这里是一个使用GNU sort的随机选项的脚本:
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