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.

What is the chmod command?

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.

More in This Category
Linux unalias Command: Remove Command Aliases

Linux unalias Command: Remove Command Aliases

Learn how to use the Linux unalias command to remove one or all aliases from the current shell session, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux reboot Command: Restart the System Safely

Linux reboot Command: Restart the System Safely

Learn how to restart the System Safely with the Linux reboot command, including practical examples, key options, and important precautions.

Linux tac Command: Print Lines in Reverse Order

Linux tac Command: Print Lines in Reverse Order

Learn how Linux tac prints records from last to first, handles multiple files and custom separators, and helps inspect recent log entries in reverse order.

Linux sort Command: Sort Text Lines

Linux sort Command: Sort Text Lines

Learn how to sort text lines with the Linux sort command, including practical examples, key options, and important precautions.

Linux uptime Command: Check Uptime and Load Averages

Linux uptime Command: Check Uptime and Load Averages

Learn how to use the Linux uptime command to check how long the system has been running and interpret load averages, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux scp Command: Copy Files over SSH

Linux scp Command: Copy Files over SSH

Learn how to copy Files over SSH with the Linux scp command, including practical examples, key options, and important precautions.

Linux timedatectl Command: Check Time Zone and Time Synchronization

Linux timedatectl Command: Check Time Zone and Time Synchronization

Learn how to check Time Zone and Time Synchronization with the Linux timedatectl command, including practical examples, key options, and important precautions.

Linux whereis Command: Locate Binaries, Source, and Man Pages

Linux whereis Command: Locate Binaries, Source, and Man Pages

Learn how Linux whereis locates binaries, source files, and manual pages, limits each search type, lists effective paths, and differs from which and find.

Linux last Command: Review Login and Reboot History

Linux last Command: Review Login and Reboot History

Learn how to use the Linux last command to review user login sessions, system reboots, and shutdown history, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux systemctl Command: Manage systemd Services

Linux systemctl Command: Manage systemd Services

Learn how to manage systemd Services with the Linux systemctl command, including practical examples, key options, and important precautions.