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...
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:
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:
It did work fine for me. There's not much complexity in that command, it's just a simple find, select/sort the proper directories, ( instead of awk , a simple tail -n could have done that), and finally remove them.
Maybe you didn't do a cd first, or you might need to check your awk version. Please reread carefully O/P's requirement :).