Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.