Press "Enter" to skip to content

Techy: Recursive CHMOD of Folders

I’m currently in the midst of moving a large number of websites from one Red Hat Linux web server (an Ensim machine) to another Red Hat Linux web server (this one powered by Cpanel) , but the chmod (file permissions) of the “public_html” (web root, web docs, htdocs whatever) folder is incorrect on the new server. So, instead of chmodding over 200 files “by hand”, I’ve used the following little script (just run from the command line):

find . -type d -name public_html -exec chmod 0755 {} \;

Basically it searches (using find recursively (ie it checks folders and sub folders/directories and sub directories) for a directory (-type d) called (-name) public_html and when it does it runs the command (-exec) chmod 0755 (which sets the permissions so that the owner can read, write and execute/open the folder and all other users can read and execute/open the folder).

Simple eh? 😉

5 Comments

  1. Oooh, recursive algorithms. We had a lecture about that last week :).

  2. twKDV twKDV

    I did not know how to use the -exec parameter and i tried chmod +x `find -type d` to make all subdirectories accessible.
    But that did not work with long filenames (with spaces and such).
    Your solution does it well!
    Thanks a lot! 🙂

  3. Recursively CHMOD Files

    I was moving a bunch of files from one location to another, and it ended up that a ton of those files had the wrong permissions. Now permissions of 755 will generally work for serving an HTML file, but it should probably be served as 644, and since it …

  4. name name

    That was just what I was searching for. I didn’t want chmod -R to change the directory priviliges as well. Thanks.

  5. U can do it with smartftp – right click folder and with chmod option.
    Just click box with ” apply on subdirs and files”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.