Posted By

magicrebirth on 12/22/09


Tagged

rm unix find


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mcloister


Command line delete matching files and directories recursively


 / Published in: Bash
 

  1. # This searches recursively for all directories (-type d) in the hierarchy starting at "." (current directory), and finds those whose name is '.svn'; the list of the found directories is then fed to rm -rf for removal.
  2.  
  3. find . -name '.svn' -type d | xargs rm -rf
  4.  
  5. # If you want to try it out, try
  6.  
  7. find . -name '.svn' -type d | xargs echo
  8.  
  9. # This should provide you with a list of all the directories which would be recursively deleted.
  10.  
  11. ==================================
  12.  
  13. # Another way is:
  14.  
  15. find . -name ".svn" -exec rm -rf {} \;
  16.  
  17. #Try something like this first to do a dry run:
  18.  
  19. find . -name ".svn" -exec echo {} \;
  20.  
  21. #Note that the empty braces get filled in with the file names and the escaped semicolon ends the command that is executed (starting after the "-exec").

Report this snippet  

You need to login to post a comment.