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.

  • 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

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 .*
  • +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.

find . -type d -iname ".*" -not -iname "." -not -iname ".."
  • 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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy