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 resolvectl Command: Inspect systemd DNS Resolution

Linux resolvectl Command: Inspect systemd DNS Resolution

Learn how to inspect systemd DNS Resolution with the Linux resolvectl command, including practical examples, key options, and important precautions.

Linux grep Command: Search Text and Filter Command Output

Linux grep Command: Search Text and Filter Command Output

Learn how to use the Linux grep command to search files for text or regular expressions and filter command output, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux info Command: Browse GNU Documentation

Linux info Command: Browse GNU Documentation

Learn how to use the Linux info command to browse hierarchical GNU manuals and navigate Info nodes, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux fdisk Command: Inspect and Edit Disk Partitions

Linux fdisk Command: Inspect and Edit Disk Partitions

Learn how to inspect and Edit Disk Partitions with the Linux fdisk command, including practical examples, key options, and important precautions.

Linux du Command: Check File and Directory Disk Usage

Linux du Command: Check File and Directory Disk Usage

Learn how to use the Linux du command to measure and summarize disk space used by files and directories, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux gzip Command: Compress a File in gzip Format

Linux gzip Command: Compress a File in gzip Format

Learn how to compress a File in gzip Format with the Linux gzip command, including practical examples, key options, and important precautions.

Linux Tutorial / Understand systemd Services, Boot, and Logs

Linux Tutorial / Understand systemd Services, Boot, and Logs

Understand Linux boot stages and systemd units, distinguish active services from boot enablement, and inspect current-boot logs with systemctl and journalctl.

How to Check the Linux Distribution, Version, Kernel, and Architecture

How to Check the Linux Distribution, Version, Kernel, and Architecture

Learn how to identify a Linux distribution and version with /etc/os-release, then check the running kernel and CPU architecture with hostnamectl and uname. The guide also covers scripts, legacy systems, containers, WSL, and chroot environments.

Linux lsblk Command: Inspect Disks, Partitions, and Mounts

Linux lsblk Command: Inspect Disks, Partitions, and Mounts

Learn how to inspect Disks, Partitions, and Mounts with the Linux lsblk command, including practical examples, key options, and important precautions.

Linux time Command: Measure Command Execution Time

Linux time Command: Measure Command Execution Time

Learn how to use the Linux time command to measure elapsed, user CPU, and system CPU time for a command, with essential options, practical examples, output interpretation, and common troubleshooting tips.