LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-13-2005, 05:38 PM   #1
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Rep: Reputation: 15
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.
 
Old 07-13-2005, 06:18 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
find -type d -a \( -iregex ".*/asdf\..*" -a ! -iregex ".*/asdf\.2" \) -exec rm -rf {} \;
 
Old 07-13-2005, 06:32 PM   #3
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
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" ?
 
Old 07-13-2005, 06:54 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,974
Blog Entries: 11

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to delete files with 0k file size in a directory justgiver Linux - Newbie 4 01-28-2008 04:56 AM
script to gzip all directories in a directory br8kwall Programming 11 09-06-2005 10:42 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
script/command to delete all symlinks from a directory reddazz Linux - General 5 03-15-2005 11:39 PM
directory renaming shell script? Apostasy Linux - General 15 02-22-2005 06:50 AM


All times are GMT -5. The time now is 12:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration