How to Change File Permissions Recursively with chmod in Linux?

File permissions must be set up and managed in multi-user systems like How to Change File Permissions Recursively with chmod in Linux? Linux guarantees that only authorized users have access to the files they are supposed to.

Use the chmod command to modify a file’s permissions. Also, it enables recursive file permission changes so that you can set numerous files and subdirectories with a single command.

You will discover How to Change File Permissions Recursively with chmod in Linux? and how to use chmod recursively in this article:

  1. A terminal window or command line (Ctrl+Alt+F2 or Alt+T)
  2. An individual with sudo rights (optional)
  3. Linux Software

Verify File Permissions

Use the following command to examine the file permissions in the working directory:

  • ls –l

All of the files in the directory’s permissions are listed in the output.

  • For instance, the Example directory has three files with identical permissions: test1.txt, test2.txt, and test3.txt (-rw-rw-r–).

According to the file permissions stated above, we know that:

  1. The owner has read-only and write-access rights.
  2. The owner’s group is granted read-and-write access.
  3. There are read-only users.

Modify Permission Successively

The standard chmod command is frequently used to modify a single file’s permissions. But, it’s possible that you’ll need to recursively change the permission for each file in a directory.

In certain circumstances, the chmod recursive option (-R or —recursive) sets a directory’s permissions (and the files it contains).

The following syntax is used to recursively change a file’s permissions:

  • [Permission] chmod -R [Directory]

As a result, you would type: to give all files in the Example directory the 755 permission.

  • Example: sudo chmod -R 755

The command grants the owner read, write, and execute rights (7) and everyone else reads and executes rights (55).

With the find Command, modify the permission

The find command can be used to give directories and files different permissions.

Using the search command to find files or directories and then passing it on to chmod to set the permission are part of the fundamental syntax:

  • using the command sudo locate [directory] -type [d/f] -exec chmod [privilege];

1: The directory path containing the files and subdirectories you want to configure should be substituted for [directory].

2: Indicate whether the search is for a file or a directory (-type d or -type f).

3: Using the numerical or symbolic modes of the chmod command, set the file’s [permission].

Do not give files the ability to run. The following commands might be run in a typical configuration:

  • executing sudo find Example -type d -chmod 755;
  • execute the command sudo find Example -type f -chmod 644;

The files in this example have 644 (u=rw,go=r) access, whereas the directories have 755 (u=rwx,go=rx) privileges.

By entering the Example directory (cd Example) and displaying the contents, you can confirm that folders and files have various permission levels (ls -l). The result should resemble the following:

Modify Particular File Permissions Recursively

How to Change File Permissions Recursively with chmod in Linux? For modifying the permissions of files of a given type, combine the search command with chmod.

The following command syntax can be used to modify a directory’s permissions for a particular file type:

  • "*. [filename extension]" search [directory] -exec chmod [privilege];

For instance, the following command might be used to make files in the current directory executable:

  • exe -name "*.sh" -chmod +x;


You should now be able to use the find command or the chmod -R command to recursively alter the file permissions on your Linux system.

How to Change File Permissions Recursively with chmod in Linux? Alternatively, you can modify the default permissions by using the umask command.




Flash Sale

Hurry Up! Offer ends in
01 days
07 hrs
08 mins
02 secs
Buy Now