How do I recursively chmod a folder in Linux?

How do I recursively chmod a folder in Linux?

Linux provides a method for controlling file permissions because it is a multi-user operating system, ensuring that only permitted programmes and users have access to certain directories and files.

The “Permission denied” message, which denotes that you do not have the required privileges, may appear while you use Linux and prevent you from changing certain files or folders.

This tutorial will teach you how to modify file permissions in Linux recursively so that your changes are made to files and subfolders as well.

How can I verify the Linux file permissions?

Check the user, group, and other permissions first if the “permission denied” error occurs during a file or directory activity.

The ls -l command can help you do this. For instance, the “/var” directory has the following permissions for various files and folders.

The data in the result above is particular.

The first column displays the permissions for files and directories. The first letter in this column designates the kind: d designates a directory, l designates a symbolic link, and – designates an ordinary file.

The remaining nine characters are separated into three groups that represent the file or directory permissions: u user, g group, and o owner. The letters r, w, and X stand for “read” privileges, “write” permissions, and “execute” permissions, respectively.

Once you have created a functioning directory or file, you may quickly change its file permissions.

How can I chmod a folder in Linux recursively?

The chmod command is the easiest way to change file permissions in Linux. The general syntax of the command is as follows:

permission chmod


The permissions given to a user, group, owner, or everyone are known as permissions.

Operator: This shows which permissions have been provided to the person who has been given that permission. It works as follows: + grants permission, – refuses permission, and = specifies which permissions should be set.

Which permissions to grant—r read, w write, or x execute—depends on the mode.

Use the following command, for instance, to stop everyone from writing to the backup directory located in the “/var” directory:

Chmod -w /var/backups with sudo

The chmod command can be used to change file permissions, although it only affects the specified

Fortunately, you can recursively change the file permissions of a directory, a file, and all of its child directories and files. To do this, issue the chmod command with the recursive -r option.

For illustration, let’s recursively revoke read access to the whole “/var/backup” directory, including all of its files and subdirectories.

Let’s use chmod to recursively change the permissions now:

“sudo chmod -r -r” for “/var/backups”

As you can see, the file permissions have now been modified.

Recursive permission change combined with find

Usually, you won’t be giving files and folders the same privileges. This is because in order to cd into a certain directory, you need to have the execute permission. However, the majority of files don’t need this execute permission.

Leave a Comment