Chmod Recursive: Change File Permissions Recursively in Linux

When you deploy a website, restore a backup, or copy project files from another machine, permissions often end up inconsistent across many files and directories. In these cases, chmod
with the -R flag lets you fix the entire directory tree in one command.
This guide explains how to use chmod -R to change permissions recursively, how to set different permissions for files and directories using find, and how to avoid common mistakes.
Understanding Permission Numbers
Linux permissions are represented by three digits. Each digit is the sum of read (4), write (2), and execute (1):
| Number | Permission | Meaning |
|---|---|---|
7 | rwx | Read, write, and execute |
6 | rw- | Read and write |
5 | r-x | Read and execute |
4 | r-- | Read only |
0 | --- | No permission |
The three digits represent the owner, group, and others, in that order. For example, 755 means the owner has full access (rwx), while the group and others can read and execute (r-x).
For a complete overview of the permission system, see Understanding Linux File Permissions .
Using chmod -R
The -R option tells chmod to apply permissions recursively to a directory and everything inside it. The general syntax is:
chmod -R MODE DIRECTORYFor example, to set 755 on all files and subdirectories under /var/www/html:
chmod -R 755 /var/www/htmlThe same change using symbolic mode:
chmod -R u=rwx,go=rx /var/www/htmlOnly the root user, the file owner, or users with sudo
privileges can change file permissions. Be careful when running chmod -R because it modifies every entry under the target directory.
Setting Different Permissions for Files and Directories
In most cases, files and directories should not have the same permissions. Directories require the execute bit so you can cd
into them, but regular files typically do not need it.
The most common pattern is 755 for directories and 644 for files. Use the find
command to target each type separately.
Using numeric mode:
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;Using symbolic mode:
find /var/www/html -type d -exec chmod u=rwx,go=rx {} \;
find /var/www/html -type f -exec chmod u=rw,go=r {} \;The find command searches for entries matching -type d (directories) or -type f (files) and passes each one to chmod via -exec.
When dealing with a large number of files, the -exec approach runs chmod once per entry. Use xargs
to pass multiple entries at once, which is significantly faster:
find /var/www/html -type d -print0 | xargs -0 chmod 755
find /var/www/html -type f -print0 | xargs -0 chmod 644The -print0 and -0 flags handle filenames that contain spaces or special characters.
Using Capital X to Add Execute Only to Directories
The capital X permission is a shortcut that adds execute only to directories and files that already have at least one execute bit set. This avoids making regular files executable:
chmod -R u=rwX,go=rX /var/www/htmlThis sets read for everyone, write for the owner, and execute only on directories — all in a single command without needing find.
Common Permission Patterns
| Pattern | Directories | Files | Use Case |
|---|---|---|---|
755 / 644 | rwxr-xr-x | rw-r--r-- | Web server content |
750 / 640 | rwxr-x--- | rw-r----- | Private web apps (group access) |
700 / 600 | rwx------ | rw------- | User-private files (SSH keys, configs) |
775 / 664 | rwxrwxr-x | rw-rw-r-- | Shared project directories |
Safety Considerations
Recursive permission changes can break your system if applied to the wrong directory. Keep the following in mind:
- Never run
chmod -R 777 /or target the root filesystem. This gives full access to every file on the system and can make the system unbootable. - Use
--preserve-rootto prevent accidental changes to/. Most modern distributions enable this by default, but you can set it explicitly:
chmod -R --preserve-root 755 /some/directory- Always double-check the target path before pressing Enter. A misplaced space in
chmod -R 755 / var/www(note the space after/) applies755to the entire root filesystem. - On GNU
chmod, recursive mode uses-Hbehavior by default. It follows a symlink only when the symlink itself is passed as a command-line argument and points to a directory. It does not traverse every symlink found during recursion. - If you need different traversal behavior, use
-Lto follow all directory symlinks or-Pto avoid following symlinks.
Verifying Permissions
To check the permissions of files and directories, use the ls
command with the -l flag:
ls -l /var/www/html/drwxr-xr-x 2 www-data www-data 4096 Feb 13 10:00 css
-rw-r--r-- 1 www-data www-data 8421 Feb 13 10:00 index.html
drwxr-xr-x 3 www-data www-data 4096 Feb 13 10:00 imagesThe first character indicates the entry type (d for directory, - for file). The next nine characters show the owner, group, and others permissions.
To verify permissions recursively, add the -R flag:
ls -lR /var/www/html/Troubleshooting
Operation not permitted
You do not have permission to change the file. Run the command with sudo or switch to the file owner.
chmod: cannot access ‘path’: No such file or directory
The target path does not exist. Verify the path with ls before running chmod.
Permissions do not change on a mounted drive
Filesystems such as NTFS and FAT do not support Linux permissions. The permissions are set at mount time via the fmask and dmask mount options instead.
Files became executable after chmod -R 755
Using 755 on everything makes regular files executable. Use find to set 755 on directories and 644 on files separately, or use the capital X shortcut.
Quick Reference
| Command | Description |
|---|---|
chmod -R 755 dir/ | Set 755 on directory tree |
chmod -R u=rwX,go=rX dir/ | Owner rw, others r, execute on dirs only |
find dir/ -type d -exec chmod 755 {} \; | Set 755 on directories only |
find dir/ -type f -exec chmod 644 {} \; | Set 644 on files only |
find dir/ -type d -print0 | xargs -0 chmod 755 | Faster directory permission change |
find dir/ -type f -print0 | xargs -0 chmod 644 | Faster file permission change |
chmod -R --preserve-root 755 /path | Prevent accidental changes to / |
chmod -R g+w dir/ | Add group write recursively |
chmod -R o-rwx dir/ | Remove all others permissions |
ls -lR dir/ | Verify permissions recursively |
FAQ
What is the difference between 755 and 644?
With 755, the owner can read, write, and execute, while others can read and execute. With 644, the owner can read and write, while others can only read. Use 755 for directories and 644 for regular files.
Does chmod -R follow symbolic links?
On GNU chmod, -R uses -H behavior by default. This means it follows a symlink only when that symlink is provided as a command-line argument and points to a directory. Use -L to follow all directory symlinks, or -P to avoid following symlinks during traversal.
Can I undo a recursive chmod?
There is no built-in undo. If you change permissions on the wrong directory, you must restore them manually or from a backup. Always verify the target path before running chmod -R.
What does chmod -R 777 do?
It gives full read, write, and execute permissions to everyone on every file and directory in the tree. This is a serious security risk and should never be used on system directories.
What does capital X mean in chmod?
Capital X adds execute permission only to directories and files that already have an execute bit set. It is useful for applying permissions recursively without making regular files executable.
Conclusion
The chmod -R command changes permissions recursively across an entire directory tree. For most use cases, combine find with chmod to set different permissions for files and directories, or use the capital X shortcut for a single-command approach.
If you have any questions, feel free to leave a comment below.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page