There is a way to do it — we can chain xargs
-find
-xargs
-chmod
:
# Find unwritable files and chmod them
xargs -I {} -0r -a $FILE_LIST find {} ! -perm -u+w -print0 | xargs -0r chmod -R 700 -v
The full Bash script, thus, would be:
FILE_LIST=`mktemp --suffix=.list`
find ~/udit65_backup/ -maxdepth 1 -iname "$PREFIX-*" -type d -mtime +$NDAYS -print0 > $FILE_LIST
# Make unwritable files... writable
xargs -I {} -0r -a $FILE_LIST find {} ! -perm -u+w -print0 | xargs -0r chmod -R 700 -v
xargs -0r -a $FILE_LIST rm -rf -v
rm -f $FILE_LIST