i'm trying to delete in gnu/linux all folders inside another folder that start with a "." (dot), for that i'm using the find utility, this is what i have:

find . -iname ^\..* -exec rm -rf {} \;

but it doesn't do anything :(. I'm already tested the regular expression and works well. Any help please??

thank's a lot for your time.

link|improve this question
5  
Be very careful. There is a . and .. file in every directory which will likely cause you grief when you rm -rf it :-) – paxdiablo Jul 14 '10 at 0:46
thanks for the information, i read it too late :( i deleted a very important work i was doing, so all again :(. But i will keep in mind the next time – fkn_man Jul 14 '10 at 2:16
feedback

migrated from stackoverflow.com Jul 15 '10 at 4:24

This question came from our site for professional and enthusiast programmers.

4 Answers

find uses globbing syntax, and you can use -type d to find just directories:

find . -type d -name '.?*' | vim -

You need to be extremely careful when globbing or using regex to find .hidden files, as you can quite easily pick up . and delete your whole folder, or even worse, match .. and you delete your whole parent folder. Consider the consequences of the following command:

/home/someuser bash$ rm -rf .*
link|improve this answer
+1 for the "be careful" comment alone! I'm not usually prescient but I saw much angst and gnashing of teeth in fkn_man's future :-) – paxdiablo Jul 14 '10 at 1:06
feedback

-name and -iname use globs, not regexs. Try -regex or -iregex instead.

link|improve this answer
feedback
find . -type d -iname ".*" -not -iname "." -not -iname ".."
link|improve this answer
Find doesn't list .., so you only need to exclude the first. – Roger Pate Jul 15 '10 at 4:06
You don't need to exclude either with -mindepth 1. – Ignacio Vazquez-Abrams Jul 15 '10 at 4:25
feedback

If zsh is an option, you can simply use: print **/.*(/) or rm of course :)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown