Archive

Archive for the ‘Linux’ Category

recursive find and delete on linux

September 30, 2009 2 comments

Today I have come across a problem where, I have a folder (say users) and inside users i have folders for each user (Ex Jhon, Seena etc..) and inside each user folder i have a svn folder. (I’m running Ubuntu)

Users ->

Jhon

-> a.svn

seena

-> b.svn

And my requirement was to  remove all the svn folders. So heres how i did that (this code spinet was given one of my collegues). And heres how you can do it

go to the required folder (Ex: Users)

and open up a command prompt

type this command

find . -name “*.svn” -exec rm -rf ‘{}’ \;

and that should do the magic 🙂

So let me explain the command

find . -name “*.svn” -exec rm -rf ‘{}’ \;

find -> will find the files we are requesting

.      -> means the current folder (you can give any folder you want)

-name  -> what is the characteristic to find (in this case its find by name)

“<you files>”  -> name of the files (*.svn means all the files which has .svn extension)

-exec              -> this will execute the next command which we give

rm                -> remove command

-rf                -> r means recursive (since these are folders) and f means FORCE since .svn files are read only

‘{}’               -> this tells the system to get what ever the parameters which sent by our earlier find command

\                 -> do this action recursively

hope this helps 🙂

Categories: Linux Tags: