How to force permissions of CURRENT for all subdirectories in Linux?

I often find myself in a situation where I go into the shell as root (they already tell me that this is bad practice) and copy the new files to some directory served by apache.

Since I am logged in as the root user, the new files will have the root set as the owner and different permissions than the files that are already present, and I will need to change the permissions for Apache to have access to the files. I do it manually.

I will explore the best way to do this. I was wondering if there is a way to somehow apply the permissions of the current folder to all its subfolders and files with one command.

Windows has a feature where you can "reset allow all files and folders" to the parent folder's folder.

+4
source share
2 answers

To get permissions for the current directory, you can use

stat -c %a . 

To set permissions recursively, use

 chomd -R 

Putting it together, he gives

 chmod -R `stat -c %a .` . 

Or, you can use the --reference chmod --reference , if supported.

 chmod -R --reference=. . 
+4
source

+ 1'd @choroba answer, but ... are you sure you want to do?

From http://en.wikipedia.org/wiki/File_system_permissions ...

Access rights
Unix-like systems implement three specific permissions that apply to each class:

  • Read permission provides the ability to read a file. When installing for a directory, this permission makes it possible to read the names of files in the directory, but not to learn any additional information about them, such as contents, file type, size, ownership, permissions.
  • Write permission provides the ability to modify the file. When installing for a directory, this permission provides the ability to modify entries in the directory. This includes creating files, deleting files, and renaming files.
  • Execution permission provides the ability to execute a file. This permission is required for executable programs, including shell scripts, in order to run them. When installing for a directory, this permission provides access to the contents of the file and meta-information if its name is known, but not the list of files inside if the read value is not specified.

The effect of setting permissions for a directory, not a file, is "one of the most frequently misunderstood file issues."

If permission is not established, the corresponding rights are prohibited. Unlike ACL-based systems, permissions on Unix-like systems are not inherited. Files created in a directory are not necessarily the same permissions as this directory.

(highlighted by me)

0
source

Source: https://habr.com/ru/post/1432020/


All Articles