Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

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

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

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

4 Answers 4

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 .*
share|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

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

share|improve this answer
find . -type d -iname ".*" -not -iname "." -not -iname ".."
share|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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.