How to chmod only on subdirectories?
You can use wildcards on the top level directory.
chmod 774 d*/workspace
Or to make it more specific you can also limit the wildcard, for example to d
followed by a single digit.
chmod 774 d[0-9]/workspace
A more general approach could be with find
.
find d* -maxdepth 1 -name workspace -type d -exec chmod 774 "{}" \;
In a shell like bash
you can use its extended globbing option to first mark all the directories named workspace
and chmod
it in one shot
shopt -s nullglob globstar
The option nullglob
is to make sure the glob expansion does not throw any error when it does not find any files in the path. Also this will ensure the empty glob string is not included as part of the array. The globstar
option is enabled for recursive globbing.
Now mark those directories in a shell array as
dirs=(**/workspace/)
As one more sanity check, you could first print the array to see if all the directories required are taken care. See if all the directories are listed below when you do the below printf()
command,
printf '%s\n' "${dirs[@]}"
This will populate the array with all recursive workspace
folders, now we need to use chmod
on it
(( "${#dirs[@]}" )) && chmod -R 774 -- "${dirs[@]}"