48

In Ubuntu I want to change the file permissions of a whole folder and all its sub folders to read/write by anybody

I have tried sudo chmod 666 /var/www and sudo chmod 755 /var/www without success

update

I have since found that changing privileges can also be done in the GUI by opening nautilus as sudo.

megaman
  • 889
  • 1
  • 13
  • 19
  • Don't do that. You are opening a security hole. You could do `chmod -R` – Basile Starynkevitch Apr 23 '14 at 18:07
  • For changing permission, you need to become a root then you can do chmod +x filename it is already explained here [how to become root and give full permission to a file](http://goo.gl/s7wWBa) I hope it would help you out! – Himanshu Tewari Jun 01 '15 at 06:36

3 Answers3

90

So that you don't mess up other permissions already on the file, use the flag +, such as via

sudo chmod -R o+rw /var/www

16

If you just want to change file permissions, you want to be careful about using -R on chmod since it will change anything, files or folders. If you are doing a relative change (like adding write permission for everyone), you can do this:

sudo chmod -R a+w /var/www

But if you want to use the literal permissions of read/write, you may want to select files versus folders:

sudo find /var/www -type f -exec chmod 666 {} \;

(Which, by the way, for security reasons, I wouldn't recommend either of these.)

Or for folders:

sudo find /var/www -type d -exec chmod 755 {} \;
lurker
  • 55,215
  • 8
  • 64
  • 98
  • Or `sudo find /var/www -type f -exec chmod o+rw {} \;` but it's still a terrible idea security wise. – Elliott Frisch Apr 23 '14 at 18:12
  • @ElliottFrisch yes that would be preferred for changing permissions to `o+rw` on just files. And I agree about the security! – lurker Apr 23 '14 at 18:14
  • Good call on separating between files/folders. I assumed that he wanted the 'other' user to be able to write files into each dir, but that might not be the case. –  Apr 23 '14 at 18:15
-3

Add -R for recursive:

sudo chmod -R 666 /var/www
lurker
  • 55,215
  • 8
  • 64
  • 98
user973783
  • 113
  • 7
  • 2
    Incorrect. This will overwrite anything he had set on user/group and set it to rw. This will break `cd`-ing into directories. –  Apr 23 '14 at 18:11
  • Yo man.. don't use "/"+sudo at anytime. Once I have destroyed a whole server running 10 websites by changing permission for whole directory. Give the folder name appropriately. – Ganesh Babu Apr 11 '16 at 09:37