4

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.

2
  • 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, 2010 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, 2010 at 2:16

4 Answers 4

5

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
  • +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, 2010 at 1:06
1

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

0
find . -type d -iname ".*" -not -iname "." -not -iname ".."
2
  • Find doesn't list .., so you only need to exclude the first.
    – Roger Pate
    Jul 15, 2010 at 4:06
  • You don't need to exclude either with -mindepth 1. Jul 15, 2010 at 4:25
0

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

You must log in to answer this question.