The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 05-15-2008
rubin's Avatar
rubin rubin is offline
Registered User
 

Join Date: Nov 2007
Posts: 151
Quote:
Originally Posted by Stephan View Post
...I want to write a script, that will delete all directories within /data/exports/ but not the 2000,2001 and 2002 found at that first level. The 200x found within daily and etc i want gone though.
...
any thoughts, help appreciated.

If you were on Linux, things would have been easier by using -mindepth option of GNU find. In this case we need first to sort the directories that aren't needed:

Code:
cd /data/exports/

find . -type d | awk '!/\.\/200*/' | xargs -p rm -r

Test it first, by removing rm -r part, ( -p will prompt you ), to see if you have the all the desired directories. If you need the dirs that are named as numbers 200x, then change the find part to:

Code:
find . -type d -name "200*"
Reply With Quote