#!/bin/bash let FILECOUNT=$RANDOM%`ls | wc -l`; echo $RANDOM%$FILECOUNT for i in $(ls); do if [ $FILECOUNT -gt 1 ]; then let FILECOUNT-=1; else file $i # echo $i cd $i if [ $? -eq 0 ]; then dirrand; fi exit; fi done