The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Protecting the directory tree rooneyl UNIX for Dummies Questions & Answers 2 02-17-2008 05:59 PM
directory tree ravi raj kumar Shell Programming and Scripting 3 01-24-2008 01:08 PM
setup directory tree wicked24 Shell Programming and Scripting 2 11-15-2007 03:07 AM
directory as tree anything2 High Level Programming 2 03-01-2007 09:38 AM
Directory tree search??? solvman High Level Programming 3 09-28-2001 02:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-29-2007
blane blane is offline
Registered User
  
 

Join Date: May 2007
Location: Roanoke, VA
Posts: 11
Searching directory tree

I'm currently trying to write a script that will do the following:

search a given directory tree for a file with MMDDYYYY in the name.
delete those files only.

I can't figure out how to make the script delete the files with the MMDDYYYY in the filename after finding them.

Should I export it to another file, have the script read the file and then delete the entries? If so, how?

Thanks in advance!
  #2 (permalink)  
Old 05-29-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Find & Remove

Hope this is what you are looking for,


Code:
find . -name '*MMDDYYYY*' -type f  -exec rm -i {} \;

I have added the option -i to the rm command.Incase you are sure to remove all the pattern matched files take out the "-i" and try.

Thanks
Nagarajan G
  #3 (permalink)  
Old 05-29-2007
blane blane is offline
Registered User
  
 

Join Date: May 2007
Location: Roanoke, VA
Posts: 11
Thanks for the reply.

When I run that I'm getting an error which says:

syntax error near unexpected token `('

If I take out the
Code:
-exec rm () \;

then it works fine to find the files.
  #4 (permalink)  
Old 05-29-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Quote:
Originally Posted by blane
Thanks for the reply.

When I run that I'm getting an error which says:

syntax error near unexpected token `('

If I take out the
Code:
-exec rm () \;

then it works fine to find the files.
I guess you have misspelled it is {} and not ()

Thanks
Nagarajan Ganesan.
  #5 (permalink)  
Old 05-29-2007
blane blane is offline
Registered User
  
 

Join Date: May 2007
Location: Roanoke, VA
Posts: 11
You're exactly right. I had just figured it out and was going to post that up when I saw you've replied.

Thanks again
  #6 (permalink)  
Old 05-29-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
The choice of file name must be clarified :

Code:
find . -name '*[01][0-9][0-3][0-9][0-9][0-9][0-9][0-9]*' -type f -exec rm -i {} \;

Jean-Pierre.
  #7 (permalink)  
Old 05-29-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by aigles
The choice of file name must be clarified :

Code:
find . -name '*[01][0-9][0-3][0-9][0-9][0-9][0-9][0-9]*' -type f -exec rm -i {} \;

Jean-Pierre.
that would make '19392007' valid.... need to work out the valid regex (accounting for the leap years as well.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0