Right now, I have a script that runs daily that chmod's the home directories, removing all "other" permissions from the directories and the "group" write permission. See below.
#Removing all other permissions on all home directories and write from group
ls /home | sed 's/ //g' |
while read i; do
chmod -R o-rwx /home/$i
chmod -R g-w /home/$i
done
This works great; however, I would prefer if the script checked if there were any files that needed to be changed and then act upon them instead of just doing it every time, regardless if it needs it.
I assume I could put this whole thing in a sub function inside of a if
statement, but I don't know what test I would run inside that if
statement.
How can I test if the directories would need changed?
for dir in /home/*/; do chmod -R g-w,o-rwx "$dir"; done
unless you want to do something else with the files with extra permissions, like get a listing of them before fixing the permissions. – ilkkachu Aug 06 '18 at 18:38setfacl
. https://unix.stackexchange.com/questions/1314/how-to-set-default-file-permissions-for-all-folders-files-in-a-directory – BufferOverflow Aug 07 '18 at 22:41