LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   shell script: delete all directories named directory.# except directory.N (http://www.linuxquestions.org/questions/programming-9/shell-script-delete-all-directories-named-directory-except-directory-n-342926/)

brian0918 07-13-2005 05:38 PM

shell script: delete all directories named directory.# except directory.N
 
What would be the easiest way in a script that can run in bash (and preferably ksh and csh too) to delete all directories named asdf.# (where # is 1, 2...10...100...1000), except for asdf.N where N is some number?

For example, if i have directories asdf.1 asdf.2 asdf.3, and i want to delete all but asdf.2


Thanks.

Tinkster 07-13-2005 06:18 PM

find -type d -a \( -iregex ".*/asdf\..*" -a ! -iregex ".*/asdf\.2" \) -exec rm -rf {} \;

brian0918 07-13-2005 06:32 PM

This works properly, but gives me these "errors":

find: ./asdf.1: No such file or directory
find: ./asdf.3: No such file or directory


Is there a way to supress this, or another way to do it that doesn't report any "errors" ?

Tinkster 07-13-2005 06:54 PM

Quote:

Originally posted by Tinkster
find -type d -a \( -iregex ".*/asdf\..*" -a ! -iregex ".*/asdf\.2" \) -exec rm -rf {} \; 2>/dev/null
:}


All times are GMT -5. The time now is 08:38 PM.