Linux chmod Command: Change File and Directory Permissions

chmod changes the read, write, and execute permissions of files and directories. You can use either numeric mode or symbolic mode, and it is safe to check the current permissions of the target before making changes.

Permissions apply separately to the owner, the group, and others. For regular files, the execute bit determines whether it can be executed, and for directories, the execute bit controls whether the path can be traversed and whether you can access the contents inside. The command to change ownership is chown.

Basic syntax

chmod [options] mode file...

Installed implementations and options may vary depending on the distribution. Check the description for your current system with man chmod.

Examples

Adding execute permission in symbolic mode

Adds execute permission only to the owner while keeping other permissions the same.

chmod u+x script.sh

Specifying permissions in numeric mode

Allows the owner to read and write, and allows the group and others to read only.

chmod 644 report.txt

Check before and after changes

Check the mode of the target file after changing permissions.

ls -l report.txt
chmod go-rwx report.txt
ls -l report.txt

Check whether the permission numbers have actually been applied

640 means owner read/write, group read, no permissions for others. The following example applies it only to a file you created yourself and then checks it with stat.

printf 'demo\n' > demo.txt
chmod 640 demo.txt
stat -c '%a %n' demo.txt

Example output:

640 demo.txt

Even if chmod itself succeeds, it usually doesn't output anything. For directories, the execute bit represents entry/search permission, so mechanically applying the same numbers as for a file can cause access issues. Check the target path and its sub-items before making recursive changes.

A numeric mode sets the permission bits as a whole, while a symbolic mode such as chmod g+w file changes only the requested bits. In a shared directory, inspect owner, group, and other permissions together, and decide whether the file truly needs its execute bit.

Main Options and Format

Options/Format Description
u/g/o/a Refers to owner, group, others, and all.
+ / - / = Refers to adding, removing, or assigning permissions.
r/w/x Refers to read, write, and execute permissions.
-R Change recursively for subdirectories and files.
--reference=file Apply the same mode as the reference file.

Precautions when using

chmod -R 777 gives extensive access to all users, so do not use it for convenience. Files and directories require different permissions. Before making recursive changes, check the target scope with find or ls, and also look at access controls beyond default modes, like ACL and SELinux.

Frequently Asked Questions

What does chmod 755 mean?

The owner has read, write, and execute (7), while the group and others have read and execute (5). Applying it the same way to regular files and directories has different implications.

Official Documentation

You can check the exact behavior of the options and differences by implementation in the official chmod documentation.