'When we use -R with chmod or chown will it affect the files which might get added to the directories in the future?

So i know that whenever we use

  • chmod -R xxx directory_name
  • chown -R user:group directory_name

it affects all the files which are currently there in the directory. But my question is, will the commands also affect the permissions and ownership of files that are going to be added to this directory in the future?



Solution 1:[1]

Quick answer is no.

The chmod/chown command with -R parameter will influence the directory and his content for now, not in the future.

You can see the following example proving my point:

$ sudo mkdir /tmp/newDir
$ ll /tmp/| grep newDir
drwxr-xr-x 2 root   root   4096 Apr  4 18:01 newDir

$ sudo chown -R eliott /tmp/newDir/
$ ll /tmp/| grep newDir
drwxr-xr-x 2 eliott root   4096 Apr  4 18:01 newDir

$ sudo touch /tmp/newDir/newFile
$ ll /tmp/newDir/
total 0
-rw-r--r-- 1 root root 0 Apr  4 18:02 newFile
$ ll /tmp/| grep newDir
drwxr-xr-x 2 eliott root   4096 Apr  4 18:02 newDir

In this example you can see that:

  1. I am creating a directory as owned by root user
  2. I am 'chowning' the same directory to be eliott user
  3. I am creating a file into this directory as root user

Pay attention that the file is owned by root and not eliott!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eliott Kespi