Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've just upgraded my development machine and have moved over a website I was working on. However, the permissions don't seem to have moved over properly. The dev machine is a Linux machine which runs Apache, where all the folders and sub-folders were set to 755 and all the files and files within all sub folders were set to 644.

Instead of me having to run the commands:

chmod 755

chmod 644

Is there a quicker way of doing this without having to do each and every file and folder individually?

share|improve this question
up vote 4 down vote accepted

for files:

find -type f -exec chmod 0644 {} \; 

for dirs:

find -type d -exec chmod 0755 {} \; 
share|improve this answer
You can do that in one command – AD7six May 11 '12 at 21:54

If the problem is that the files are not readable by everyone:

chmod -R a+rX /var/www

(Note the capital X, meaning that only directories and files that are executable by at least one user are made executable).

If the problem is that the files are writable by users other than the owner:

chmod -R go-w /var/www

If the problem is that files are executable, and you don't want to have any executable file: chmod -R a-x won't do it, because directories need to remain executable (the execution permission for a directory controls whether you can access files inside it). You need to be more discriminating. In zsh, you can run chmod a-x /var/www/**/*(.), using the **/ syntax to recurse into subdirectories and the . glob qualifier to match only regular files. In any shell, you can use find:

find /var/www -type f -exec chmod a-x {} +
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.