Linux Swiss army knife one liners [ Delete all the directories with specific extension]

  • 26 September 2013
  • mohit.aghera
Now a days i am using GIT for version control, so I had old repositories which contains .svn folders.
I wanted to remove all the .svn directories from the system.
 
While googling i found one useful command to delete all the directoris with one line,,
 
SYNTAX in Current Working Directory:
find . -type d -name <dir_name> -print0 | xargs -0 rm -rf
 
Example:
find . -type d -name .svn -print 0 | xargs -0 rm -rf
 
 
Explanation:
Find command takes many arguments.
I want to find all the directories starting with .svn so i used -type option
You can use -type with d option to specify the directory.
 
 
find . -type d -name .svn -print0  command will fetch all the directories starting with .svn
 
Now we are piping it with xargs
 
xargs command is designed to construct argument lists and invoke other utility. xargs reads items from the standard input or pipes, delimited by blanks or newlines, and executes the command one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored.
 
Now by using rm command we will delete the files/folders.

Comments

Henry Lara's picture

I get that type of information written in such an ideal means? angel The Dark Knight Rises Bane Coat

 

 

Jacob Tyler's picture

I’m interested in your blog and wish to write one.  Send me an email if you are willing to, thank you.  leatherp.com

 

 

itchy skin's picture

You actually make it seem so easy along with your presentation however I find this topic to be
really something which I feel I would by no means understand.
It sort of feels too complex and very broad for me.
I am looking ahead to your subsequent put up, I'll try to
get the cling of it!

Add new comment