chmod(2) - perldoc - phpman

Look up a command

 

Markdown Format | JSON API | MCP Server Tool


TLDR: chmod (tldr-pages)

Change the access permissions of a file or directory.

  • Give the user who owns a file the right to execute it
    chmod u+x {{path/to/file}}
  • Give the user rights to read and write to a file/directory
    chmod u+rw {{path/to/file_or_directory}}
  • Remove executable rights from the group
    chmod g-x {{path/to/file}}
  • Give all users rights to read and execute
    chmod a+rx {{path/to/file}}
  • Give others (not in the file owner's group) the same rights as the group
    chmod o=g {{path/to/file}}
  • Remove all rights from others
    chmod o= {{path/to/file}}
  • Change permissions recursively giving group and others the ability to write
    chmod {{-R|--recursive}} g+w,o+w {{path/to/directory}}
  • Recursively give all users read permissions to files. Also give eXecute permissions to files that have at least one execution permission and to all sub-directories
    chmod {{-R|--recursive}} a+rX {{path/to/directory}}
    chmod LIST
            Changes the permissions of a list of files. The first element of
            the list must be the numeric mode, which should probably be an
            octal number, and which definitely should *not* be a string of
            octal digits: 0644 is okay, but "0644" is not. Returns the
            number of files successfully changed. See also "oct" if all you
            have is a string.

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

            On systems that support fchmod(2), you may pass filehandles
            among the files. On systems that don't support fchmod(2),
            passing filehandles raises an exception. Filehandles must be
            passed as globs or glob references to be recognized; barewords
            are considered filenames.

                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 qw( :mode );
                chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
                # Identical to the chmod 0755 of the example above.

            Portability issues: "chmod" in perlport.


Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 18:22 @216.73.216.151 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 TransitionalValid CSS!