You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
658 B
Perl

#!/usr/local/bin/perl -w
use Getopt::Long;
my $ret = GetOptions ("f|filename:s", "p|permission:s");
my $filename = $opt_f || die "Usage: $0 -f filename -p Permission\n";
my $newPerm = $opt_p || die "Usage: $0 -f filename -p Permission\n";
# Does the file exist?
if (! -e $filename)
{
print "The file $filename does not exist.\n";
exit;
}
# Translate the string mode to an octal value
my $mode = oct($newPerm);
# Change the permissions of the file.
if ((chmod $mode, $filename) != 1)
{
print "Error: Could not change permissions on $filename : $!\n";
}