I want to make a script that browses my entire tree and delete all hidden files (ex ".git") except some (ex ".@__thumb"). I made a script that browses my tree and deletes all my files starting with a ".".
Here it is:
find . -depth -type d -name '.*' |
while read f
do
dn=`dirname "$f"`
bn=`basename "$f"`
mv "$dn/$bn" "$dn/${bn//.}"
done
I then wanted to adapt it and add a condition so that when my folder/file is called ".@__thumb" for example (which is a folder I don't want to delete) it doesn't delete the ".
I got this:
thumb=".@__thumb"
echo $thumb
find . -depth -type d -name '.*' |
while read f
do
if [[ $bn != $thumb ]]
then
dn=`dirname "$f"`
bn=`basename "$f"`
mv "$dn/$bn" "$dn/${bn//.}"
fi
done
However, my condition seems to be useless. My script still deletes my ".@__thumb" folder. Do you have any idea where the problem could be coming from or any idea for improvement? I don't know if I was clear in my explanation. If you have any questions, don't hesitate. Thank you very much.
find
won't work if one of the found files has a name that includes white space. It's bad practice; usefind
option-exec
instead.bn
is not set initially, and I don't see it deleting anything. If you want to find out what happens, add anecho $bn
at the beginning of the loop.