change permissions of a folder and everything in it
Give a folder, its subfolders and its files the permissions or the owner they need, without making them open to everyone.
danger Steps marked in red delete, overwrite or stop something. Read each one before you run it.
Steps
-
ls -ld foldersee the folder's permissions and owner now
-
chmod -R u+rwX,go+rX folderdanger you can read and write everything; others can read, and enter the folders
-
find folder -type d -exec chmod 755 {} +folders: rwx for you, r-x for everyone else
-
find folder -type f -exec chmod 644 {} +files: rw for you, read-only for everyone else
-
sudo chown -R NAME:GROUP folderdanger give the folder and everything in it to another owner
-
chmod +x script.shlet a file be run as a program
Notes
chmod -R 777lets every user change and delete everything: it is almost never the fix.- Capital
Xinu+rwXadds the x only to folders and to files that already had it.
Commands used
chmodchownfindls
Each has a page in lore: lore chmod opens it.
Related recipes
- check a file's permissionsSee who may read, write and run a file or a folder, and why a path is refused.
- who is logged inSee who is on this machine now, who was before, and the failed attempts.
- add a userCreate an account with a home folder and a password, and let it use sudo if it should.
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.