![]() |
|
|
|
|
|||||||
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. Shell Script Page. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| shell script to delete directories... | Stephan | Shell Programming and Scripting | 8 | 05-18-2008 08:00 AM |
| How to delete files in UNIX using shell script | theguy16 | Shell Programming and Scripting | 7 | 04-09-2008 01:40 AM |
| shell script for delete old files | krishnarao | Shell Programming and Scripting | 1 | 07-07-2006 07:21 AM |
| need some help with a script to delete directories. | centrino | Shell Programming and Scripting | 1 | 12-12-2005 05:33 PM |
| Need Help: Delete a file by Shell Script | r3edi | Shell Programming and Scripting | 5 | 07-11-2005 04:13 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
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"? |
|
|||
|
Code:
find . -type d | grep -v '[0-9][^/*]$' | xargs rm You could also play around with find -type d \! -name '*[0-9]*' |
| Thread Tools | |
| Display Modes | |
|
|