Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have ubuntu installed on my local computer with apache / php / mysql.

I now have a directory at /var/www - inside which I have several of my ongoing projects. I also work with opensource ( drupal, magento, sugarcrm ).

The problem I am facing is changing file permission with terminal. Sometime I need to change the permission of entire folder and its subsequent sub-folders and files. I have to individually change using

sudo chmod 777 foldername

How can I do this recursively.

Also why do I have to always do it 777, I tried 755 for folders and 644 for files, but that won't work.

share|improve this question
add comment

4 Answers

up vote 20 down vote accepted

Just add the -R option to recursively change the permissions of files. An example, recursively add read and write permissions for the owner and group on foldername:

chmod -R ug+rw foldername

Permissions will be like 664 or 775.

Setting the permissions to 777 is highly discouraged. You get errors in either Apache or your editor regarding permissions because apache runs under a different user (www-data) than you.

If you want to write to /var/www, add yourself to the www-data group and set umask+permissions accordingly.

  • Add yourself to the www-data group: sudo adduser your-username www-data
  • Change the ownership of the files in /var/www: sudo chown -R www-data:www-data /var/www
  • Change the umask, so newly created files by Apache grants write permissions to the group too. Add umask 007 to /etc/apache2/envvars.
  • Grant yourself (technically, the group www-data) write permissions: sudo chmod -R g+w /var/www.
share|improve this answer
add comment

bruteforce:

sudo find foldername -exec chmod a+rwx {} ";"

What does not work? Be more specific!

sudo find foldername -type d -exec chmod 755 {} ";"
sudo find foldername -type f -exec chmod 644 {} ";"
share|improve this answer
    
when you're inside the folder, remove "foldername" –  Enrique Feb 11 at 13:12
add comment

You can change the subfolders and files on Nautilus. As you can see on the image below. In order to have the permissons on buttons, you can enable the option on Ubuntu Tweak.

enter image description here

share|improve this answer
    
Use LANG=C [command] to get English translations. –  Lekensteyn Mar 16 '11 at 15:17
add comment

You should not need 777 for anything. Worst case, you'll need to change the owner of certain files and directories to the "www-data" user.

sudo find /var/www -type d -print0 | xargs -0 chmod 755
sudo find /var/www -type f -print0 | xargs -0 chmod 644
sudo find /var/www/some/subset -print0 | xargs -0 chown www-data:www-data

If you're using Lekensteyn's group membership method, change 755 to 775 and 644 to 664 respectively above, and then force the group stickiness:

sudo find /var/www/some/subset -type d -print0 | xargs -0 chmod g+s
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.