CUBISTCODE

CUBISTCODE

getrandfile.bash - random file or directory utility

#!/usr/bin/env bash

# desc:
#     Get a random file/dir from cwd. This script
#     requires randomise.bash which is available from
#     shellarchive.co.uk.
#
# options:
#     none
#
# usage:
#     getrandfile.bash [TYPE]
#     $ getrandfile.bash
#     $ getrandfile.bash f # return a file
#     $ getrandfile.bash d # return a dir
#
# todo:
#     Should be much more configurable.
#     _Really_ needs to return 1 on failure!
#
# author:
#     Phil Jackson (phil@shellarchive.co.uk)

find . -maxdepth 1 -type "${1:-f}" \! -name '.*' | \
    randomise.bash | tail -n 1


Tags: file, random, scripts

Rate This Article:



Privacy Policy | Copyright/Trademark Notification