How to quickly chmod files and directories selectivly

I recently had to secure a number of samba file shares which contained a few thousand directories and files. I wanted a quick way to set the permissions on all the files and then turn around and set the permissions on the folders but in a different manner. The following command will recursively search though a folder and find all files and change their permissions to the octal permission 664:

sudo find . -type f -exec chmod 0664 {} \;

Likewise we can change the search type to directories and change their permissions to 775.

sudo find . -type d -exec chmod 0775 {} \;

Leave a Reply

Your email address will not be published. Required fields are marked *