# This is executed during the CT320 DiskFull lab. # It fills the directory /tmp/full with a number of files of various # names, sizes, permissions, and dates. perl <<'END' use 5.18.1; use warnings; use File::Path qw(make_path remove_tree); use List::Util 'shuffle'; use Fatal qw(chdir chmod mkdir open syswrite utime); srand 42; # Make tree consistent for all students # Get a list of random five-letter non-plural words: open my $dict, '/usr/share/dict/words'; my @words = (shuffle grep {/^[[:lower:]]{5}$/ && !/s$/} <$dict>)[1..1000]; chomp @words; my $dir='/tmp/full'; umask 0; remove_tree($dir); mkdir $dir; chdir $dir; my $line = "All work and no play makes Jack a dull boy.\n"; my $content = $line x (2**20/length($line)+1); # 1MB of data my @suffixes = ('.bad', '.c', '.new', '.perl', '.py', '.save', '.txt', ''); my ($first, $last); for (@words) { /^.(.)(.)(.)/; # Match chars 2–4 in random word my $subdir = "$3/$2/$1"; # E.g., e/v/i/ for river make_path($subdir); my $fname = "$subdir/$_" . $suffixes[rand @suffixes]; open my $fh, ">$fname"; syswrite $fh, $content, rand length $content; syswrite $fh, "\nredrum\n", 8; # Ensure that file ends with a newline. chmod 0600|rand 0177, $fh; # u=rw + other random bits utime time() - rand(365*24*60*60), time() - rand(365*24*60*60), $fh; $first ||= $fname; # Set only if not already set. $last = $fname; # Set this one every time. } link $first, "$dir/hardlink"; symlink $last, "$dir/symlink"; say "$dir contains " . @words . " files."; END