Checks the permissions of a file
#!/usr/local/bin/perl -w
use Getopt::Long;
my $ret = GetOptions ("f|filename:s");
my $filename = $opt_f || die "Usage: $0 -f filename\n";
# Check if the file exists
if (! -e $filename)
{
print "The file $filename does not exist.\n";
exit;
}
# Perform a stat on the file.
my $perms = (stat ($filename))[2] & 07777;
printf "The octal permissions of the file $filename are %o\n", $perms;
Related examples in the same category