Changing Permissions of Files in a Directory Recursively

How do I change permissions for a folder and its subfolders/files?

The other answers are correct, in that chmod -R 755 will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?

I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command. For example:

To change all the directories to 755 (drwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r--r--):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

Some splainin': (thanks @tobbez)

  • chmod 755 {} specifies the command that will be executed by find for each directory
  • chmod 644 {} specifies the command that will be executed by find for each file
  • {} is replaced by the path
  • ; the semicolon tells find that this is the end of the command it's supposed to execute
  • \; the semicolon is escaped, otherwise it would be interpreted by the shell instead of find

How to Recursively Change all FILE Permissions without Changing DIRECTORY (and subdirectoruy) Permissions?

An example using find:

find /path/to/dir/ -type f | xargs chmod 755

How to recursively change permissions with backup file comparing permissions

chown can be uded to change ownership of a file or firectort

chown -R root:user /dir

changes the file ownership to user

-R perform the command recursively in a directory

same for

chmod -R 600 /dir

then you specify your permission and ownership in your own format

How to recursively change file permissions only in a ruby script

You could do something like below - this will change permissions of the list of files matched by Dir.glob.

FileUtils.chmod 0400, Dir.glob('/path/to/dir/**/*')

As mentioned in this thread,

Dir.glob("**/*/") # will return list of all directories
Dir.glob("**/*") # will return list of all files

Use chmod recursively to increase permissions for files and directories below a threshold but do not change those that are already above the threshold

You can add permissions using the + operator, so to make sure they are at least 755 you can do chmod -R u+rwx,go+rx /some/path - in other words, make sure the user has read, write and executable rights, and that group and other have read and execute.

Changing permission of files on searching a directory

Your approach was slightly unsuccessful.

Since your bin directory contains another files and directories, you've to change their permission recursively.

$ find -type d -name bin -exec chmod -R 777 {} \;

I Hope, this is what you've expected in return.

Chmod 777 to a folder and all contents

If you are going for a console command it would be:

chmod -R 777 /www/store. The -R (or --recursive) options make it recursive.

Or if you want to make all the files in the current directory have all permissions type:

chmod -R 777 ./

If you need more info about chmod command see: File permission

Change all files and folders permissions of a directory to 644/755

One approach could be using find:

for directories

find /desired_location -type d -print0 | xargs -0 chmod 0755

for files

find /desired_location -type f -print0 | xargs -0 chmod 0644


Related Topics



Leave a reply



Submit