recursive random file grabber (dirrand) 4


SUBMITTED BY: Guest

DATE: March 3, 2013, 6:06 a.m.

FORMAT: Bash

SIZE: 546 Bytes

HITS: 1340

  1. #!/bin/bash
  2. # pwd
  3. let R=$RANDOM;
  4. let FILECOUNT=`ls | wc -l`;
  5. #echo "random" $R;
  6. # echo "filecount:" $FILECOUNT;
  7. if [ $FILECOUNT -eq 0 ]; then
  8. pwd
  9. fi
  10. let FILECOUNT=$R%$FILECOUNT;
  11. # echo $?
  12. for i in $(ls); do
  13. if [ $FILECOUNT -gt 0 ]; then
  14. let FILECOUNT-=1;
  15. else
  16. # file $i >/dev/null
  17. # echo $i
  18. cd $i 2>/dev/null
  19. if [ $? -eq 0 ]; then
  20. $0;
  21. else
  22. echo `pwd`"/"$i
  23. fi
  24. exit;
  25. fi
  26. done

comments powered by Disqus