chmod

chmod LISTThis function changes the permissions of a list of files. The first element of the list must be the numerical mode, as in the chmod(2) syscall. The function returns the number of files successfully changed. For example:
$cnt = chmod 0755, "file1", "file2";
will set $cnt to 0, 1, or
2, depending on how many files were
changed. Success is measured by lack of error, not by an actual change,
because a file may have had the same mode before the operation. An error
probably means you lacked sufficient privileges to change its mode
because you were neither the file’s owner nor the superuser. Check
$! to find the actual reason for
failure.
Here’s a more typical usage:
chmod(0755, @executables) == @executables
|| die "couldn't chmod some of @executables: $!";If you need to know which files didn’t allow the change, use something like this:
@cannot = grep {not chmod(0755, $_) } "file1", "file2", "file3";
die "$0: could not chmod @cannot" if @cannot;This idiom uses the grep
function to select only those elements of the list for which the
chmod function failed.
On systems that support fchmod(2), you may also pass filehandles in the argument list. On systems without fchmod(2) support, passing filehandles raises a runtime exception. To be recognized, filehandles must be passed as typeglobs ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access