I ran
/bin/find /home/user/myfiles \! -name '.htaccess' -exec rm -r {} \;
and it removed everything in myfiles
and the myfiles
directory itself if .htaccess
doesn't exist.
What I was expecting is that it would find and remove files within the directory, except for any .htacess
file.
What did I do wrong?
rm -r
on everything it finds, so it is not at all strange that it removes everything. I would also expect it to possibly emit error messages when it tries to enter directories that it has already deleted. – Kusalananda Aug 31 '22 at 17:45\! -name
clause “working fine” or is it removing the entire directory tree? – G-Man Says 'Reinstate Monica' Aug 31 '22 at 22:03.htaccess
is not present as it won't remove a non-empty directory. – Mark Lane Sep 01 '22 at 03:17