# Shell Script for going through a dir recursively and chmodding based on conditions of file type

Can any person aim me to either code or a tutorial for creating a shell script that can recursively experience a whole directory site framework (beginning at the existing functioning directory site, or offered a called for argument of where to start at) and also can:

1. Determine whether a thing is a directory site, and also if it is, chmod 755 it, or
2. Determine whether a thing is a documents (not a dir), and also chmod 644 it

I'm seeking compatibility with Ubuntu, Debian, RHEL - Based, etc, so I'm not marking this with any kind of certain language. I would certainly like this in Bash, yet if you have a ZSH manuscript, that will certainly function additionally.

8
2022-06-07 14:31:33
Source Share

I am made use of to this set - line command (will certainly recurse beginning in existing functioning directory site)

find . -type d -exec chmod 0755 '{}' + -or -type f -exec chmod 0644 '{}' +


Explanation:

find .                    # starting in curdir find
-type d                   # any directory
-exec chmod 0755 '{}'     # and chmod it to 755
+                         # (variant of -exec look find man page)
-or                       # or
-type f                   # any file
-exec chmod 0644 '{}'     # and chmod it to 644
+                         # (as above)

10
2022-06-07 14:49:39
Source

The straightforward solution:

chmod -R a+rX .


+X (note the resources X) suggests to offer the execute approval if the execute approval was currently existing for some customer. If you have a directory site tree which has the appropriate permissions for the proprietor and also you intend to make it obtainable to every person, this is the appropriate command to make use of. It not just makes directory sites globe - executable, yet additionally executable documents.

If you additionally intend to reset write permissions to proprietor just and also clear any kind of setuid/setgid little bit, make that

chmod -R a-ws,u+w,a+rX .


The necessary zsh 2 - lining, if you do not intend to make any kind of documents executable:

chmod 755 **/*(/)
chmod 644 **/*(.)

3
2022-06-07 14:48:19
Source