Perl 5 version 8.0 documentation

chmod

  • chmod LIST

    Changes the permissions of a list of files. The first element of the list must be the numerical mode, which should probably be an octal number, and which definitely should not a string of octal digits: 0644 is okay, '0644' is not. Returns the number of files successfully changed. See also oct, if all you have is a string.

    1. $cnt = chmod 0755, 'foo', 'bar';
    2. chmod 0755, @executables;
    3. $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to
    4. # --w----r-T
    5. $mode = '0644'; chmod oct($mode), 'foo'; # this is better
    6. $mode = 0644; chmod $mode, 'foo'; # this is best

    You can also import the symbolic S_I* constants from the Fcntl module:

    1. use Fcntl ':mode';
    2. chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
    3. # This is identical to the chmod 0755 of the above example.