Archive for October, 2007

Delete All Subdirectories with a Specific Name

Wednesday, October 24th, 2007

Let’s say you want to delete all the "CVS" subdirectories anywhere below a top level "/opt/project" directory.  Here is how you can do this…

  1. Execute cd /opt/project to change to the top level directory below which you wish to delete the "CVS" subdirectories
  2. Execute find -type d -name 'CVS' -ls to see a preview of all the directories that will be deleted.
  3. If the preview seems ok, you can then execute find -type d -name 'CVS' -exec rm -fr {} \; to actually delete all the subdirectories (you’ll get a No such file or directory error when executing but the subdirectories are still deleted).

Obviously, this can work with any subdirectory name as you would just replace CVS above with your subdirectory name.