Pick our brains...

How to Change Ownership & Permissions on All Files & Directories

When you need to change file and directory ownership, or file and directory permissions in bulk, these are some very handy commands to know. On most servers, you’ll need root’ish privileges to do this.

Change Ownership & Group for All Files & Directories:

find /home/your_directory/public_html -exec chown user_name:group_name {} \;

Note: the “your_directory”, “user_name”, and “group_name” are meant to be replaced with the values that you’d like to set.

Change Permissions for All Directories:

We’d like to change the permissions for all the directories to 755 (-rwxr-xr-x)

find /home/your_directory/public_html -type d -exec chmod 755 {} \;

Change Permissions for All Files:

We’d like to change the permissions for all the files to 644 (-rw-r–r–)

find /home/your_directory/public_html -type f -exec chmod 644 {} \;
  • Benjamin Turner

    Another option is to pipe the output of find to xargs:


    find /path/to/wordpress/dir -type d -print0 | xargs -0 chmod 755
    find /path/to/wordpress/dir -type f -print0 | xargs -0 chmod 644
    find /path/to/wordpress/dir -print0 | xargs -0 chown websiteowner:websiteowner

    You are effectively replacing the the -exec option of find with xargs.

    Why would you want to do this?

    The main reason to do this is to reduce the number of spawned processes. Using the find -exec method above will span a new process for each found file. For a large number of found files, this can be a lot of overhead. Using the find + xargs method means a minimum number (often just one) of processes is spawned to deal with the list of files that is passed to xargs.

    The key bit to remember when using the “find + xargs” method is to use -print0 with find and -0 (dash zero) with xargs so they correctly handle whitespace in filenames.

    There’s lots more info and opinions if you want to dive further into the differences:
    http://unix.stackexchange.com/questions/41740/find-exec-vs-find-xargs-which-one-to-choose
    http://blog.endpoint.com/2010/07/efficiency-of-find-exec-vs-find-xargs.html
    https://danielmiessler.com/blog/linux-xargs-vs-exec/