shell script to delete directories...

Hi.

I'm trying to write a script that will delete all directories found, that are not named as a "number" (year)...

here is what i mean, let's say i have within /data/exports the following directories:

/data/exports/2000
/data/exports/2001
/data/exports/2002

/data/exports/daily/2000
/data/exports/monthly/2000

/data/exports/daily/2001
/data/exports/monthly/2001

/data/exports/daily/2002
/data/exports/monthly/2002

/data/exports/blahblah/something/another/etc

and so on...

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.

So i thought about writing up a script that would list all directories within /data/exports/ and those that are not numbers, do a rm -R on it...but i can't seem to get it right...

any thoughts, help appreciated.

Thanks.

You want? ... and what did you do to resolve the problem?
man find can help you.

particularly check the -type, -name and -exec options of find command

thanks danmero?

Yogesh, i've been using the find command along with the -type d option which works fine, but i need to figure out a way to only rmdir the directories that are not numerical years. Is there a way, to filter out the directories named 2000, 2001 etc and delete all the rest? I can't seem to get it working...
Technically the way i thought of doing it was using a if "not numerical" then rmdir -fR ? But how do i write this "if"?

find . -type d |
grep -v '[0-9][^/*]$' |
xargs rm

The grep removes any line containing a number in the last component of the path name. Maybe you should run it with "xargs echo rm" first just to see that it does what you want.

You could also play around with find -type d \! -name '*[0-9]*'

Thank you Era! that is what i was looking for! Really appreciate your contribution.

This should work just fine!