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.

filessecurityusers

danger Steps marked danger delete, overwrite or stop something. Read each one before you run it.

steps
  1. ls -ld folder

    see the folder's permissions and owner now

  2. chmod -R u+rwX,go+rX folder

    danger you can read and write everything; others can read, and enter the folders

  3. find folder -type d -exec chmod 755 {} +

    folders: rwx for you, r-x for everyone else

  4. find folder -type f -exec chmod 644 {} +

    files: rw for you, read-only for everyone else

  5. sudo chown -R NAME:GROUP folder

    danger give the folder and everything in it to another owner

  6. chmod +x script.sh

    let a file be run as a program

notes
  • chmod -R 777 lets every user change and delete everything: it is almost never the fix.
  • Capital X in u+rwX adds 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.