Manual

- Overview
- Tutorials
- FAQs
- History / Changes
- License

Reference

- Language
- Functions
- Operators
- Special Variables
- Pragmas
- Utilities
- Internals
- Platform Specific

Modules

- A • B • C • D • E
- F • G • H • I • L
- M • N • O • P • S
- T • U • X

News / Blogs

- Perl Buzz
- Perl Iron Man
- Perlsphere
- Planet Perl
- TPF news
- Use Perl

See also

- CPAN
- Perl.org
- Perl.com
- Perl 5 Wiki
- Perl Jobs
- Perl Mongers
- Perl Monks

Contact

- Site designed and maintained by Jon Allen (JJ)
- http://perl.jonallen.info

- View the project page and FAQs

# chmod

Perl 5 version 10.1 documentation
Go to top

# chmod

Perl functions A-Z | Perl functions by category | The 'perlfunc' manpage

- 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 be 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.

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

  On systems that support fchmod, you might pass file handles among the files. On systems that don't support fchmod, passing file handles produces a fatal error at run time. The file handles must be passed as globs or references to be recognized. Barewords are considered file names.

          open(my $fh, "<", "foo");    my $perm = (stat $fh)[2] & 07777;    chmod($perm | 0600, $fh);

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

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

Recently read

Tools

- Preferences