Debug School

rakesh kumar
rakesh kumar

Posted on

Change File Permissions Recursively

change-file-permissions-recursively

How do you recursively adjust file and directory permissions?

$ find . -type f -exec chmod 644 {} \;
$ find . -type d -exec chmod 755 {} \;
$ chmod 707 images
$ chmod 707 images/stories
$ chown -R daemon:daemon cache
$ chown -R apache:apache cache
Enter fullscreen mode Exit fullscreen mode

Setting permission to 0755 recursive :

$chmod -R 0755 directory_NameHere
Enter fullscreen mode Exit fullscreen mode

To find all files in /home/user/demo directory

$ find /home/user/demo -type f -print
Enter fullscreen mode Exit fullscreen mode

To find all files in /home/user/demo directory with permission 777, enter:

$ find /home/user/demo -type f -perm 777 -print
Enter fullscreen mode Exit fullscreen mode

Apply new permission using the -exec option as follows:

$ find /home/user/demo -type f -perm 777 -print -exec chmod 755 {} \;
Enter fullscreen mode Exit fullscreen mode

To select directories and subdirectories use the following syntax:

$ find /var/www/html -type d -perm 777 -print -exec chmod 755 {} \;
Enter fullscreen mode Exit fullscreen mode

==================================================================

$ find . -type f -exec chmod 644 {} \;
Enter fullscreen mode Exit fullscreen mode

Image description

chmod 755

$ find . -type d -exec chmod 755 {} \;
Enter fullscreen mode Exit fullscreen mode

The command find . -type d -exec chmod 755 {} \; is a Linux command that is used to change the permission of all directories in the current directory and its subdirectories to be readable, writable and executable by the owner, and readable and executable by everyone else.

Image description
So, the purpose of this command is to set the appropriate permissions for all directories within a directory and its subdirectories. The directory permissions are important for security and control over who can access and modify directories on a system.

Here are some examples of how to use this command:

1.Change the permissions of all directories in the current directory and its subdirectories:

find . -type d -exec chmod 755 {} \;
Enter fullscreen mode Exit fullscreen mode

2.Change the permissions of all directories in the "/home" directory and its subdirectories:

find /home -type d -exec chmod 755 {} \;
Enter fullscreen mode Exit fullscreen mode

3.Change the permissions of all directories in the current directory and its subdirectories, except for the "data" directory:

find . -type d ! -name "data" -exec chmod 755 {} \;
Enter fullscreen mode Exit fullscreen mode

In this example, the ! -name "data" option is used to exclude the "data" directory from the search.

daemon Permission

chown -R daemon:daemon
Enter fullscreen mode Exit fullscreen mode

Top comments (0)