diff --git a/random_file/GNUmakefile b/random_file/GNUmakefile new file mode 100644 index 0000000..cc1e898 --- /dev/null +++ b/random_file/GNUmakefile @@ -0,0 +1,7 @@ +include GNUmakevars +all: random_file +clean: + true +install: $(BINDIR)/random_file + +include GNUmakerules diff --git a/random_file/random_file b/random_file/random_file new file mode 100755 index 0000000..1911400 --- /dev/null +++ b/random_file/random_file @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use warnings; +use strict; + +my $p = $ARGV[0] || "/"; + +for (;;) { + opendir(D, $p); + my @f = grep {! /^\.\.?$/ } readdir(D); + close(D); + if (!@f) { + # empty or unreadable directory + print "$p\n"; + exit(0); + } + my $f = $f[rand($#f + 1)]; + $p = "$p/$f"; + if (! -d $p) { + print "$p\n"; + exit(0); + } +}