The Computer Oracle

Chmod to allow read and write permissions for directory

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Peaceful Mind

--

Chapters
00:00 Chmod To Allow Read And Write Permissions For Directory
00:27 Answer 1 Score 64
01:07 Accepted Answer Score 41
01:29 Answer 3 Score 19
01:52 Thank you

--

Full question
https://superuser.com/questions/126073/c...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #permissions #chmod

#avk47



ANSWER 1

Score 64


For all users to have read and write access, that would be 0777 which is a bit dangerous, especially if you are running a webserver. Like @unwind said:

chmod -R 0777 /mydirectory Will allow all users read and write access to all files and folders within that directory

Depending on your purpose, you may want to read about sticky bits, which allow all users to create new files, but not to delete or edit other files in a directory:

chmod +t /mydirectory

Also, in case you didn't know man chmod will bring up the manual page for the chmod command, which you can search for the text "recursive" by typing /recursive




ACCEPTED ANSWER

Score 41


0775 is rarely correct for a file. The following will add the appropriate desired permissions to the appropriate type, without disturbing other existing permissions:

find somedir \( -type d -exec chmod u+rwx,g+rwx,o+rx {} \; -o -type f -exec chmod u+rw,g+rw,o+r {} \; \)

See the man page for find to help decipher that.




ANSWER 3

Score 19


That's not how the Unix protection model works, you can't set permissions recursively. You need to set them on each directory, all the way "down".

Of course you can do the setting recursively, but that only means "go through and set these permissions on all files and folders below", which is not how I understand your question.

To do do that, use the -R option to chmod:

$ chmod -R 0755 /my-cool-directory