3

I have been using the function FileUtils.chmod_R to recursively change files and directories permissions under a given path but now want to change only the file permissions and leave the directories as they are. Looking at the man page for this function I can't see how to do this and I would prefer not to do this with a bash script. Please can someone tell me if this is possible with the FileUtils.chmod_R function or would I have to write additional code to iterate over every file that exist under a given path (recursive) and then FileUtils.chmod it to the desire permission? I am a ruby newbie so please point me someplace if I am asking anything obvious

adamjth
  • 75
  • 4

1 Answers1

1

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
Community
  • 1
  • 1
Wand Maker
  • 18,476
  • 8
  • 53
  • 87
  • Thanks that worked for me. In the meantime I gone and written a definition to do this but Dir.glob saves quite a few lines of code! – adamjth Apr 22 '16 at 16:16