Aug 14, 2011
tom

Change ownership or permissions on only directories or files, recursively

Question

I’m trying to set permissions/ownership on either directories or files, recursively within a given directory, without changing the other.

E.g. I have directory /web where I want to set all the directories to 775, but the files to 664.

Is there a way to do this easily?

Answer

For files:

$ find /path/to/directory -type f -print0 | xargs -0 chmod 664

For directories:

$ find /path/to/directory -type d -print0 | xargs -0 chmod 775

Related posts:

  1. Find and delete all but N largest files in 100s of directories
  2. Change user permissions on files/directories where user = fred recursively
  3. chmod all files (including hidden files) in a directory in Linux (not recursively)
  4. How to make apache create files with certain permissions?
  5. how to change permissions of specific file type

Leave a comment