UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 4th, 2006, 08:38 AM
hamboy hamboy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 88 hamboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 29 m 18 sec
Reputation Power: 0
Removing Files

Code:
#!/usr/bin/ksh

xfolder="/serv1/apache/public/data/results"

find $xfolder -atime +0 | while read file
do
rm -f $file
done

exit


hi...i'm trying to write a ksh to delete the files in /serv1/apache/public/data/results folder... but it says:
Quote:
produced the following output:

rm: /serv1/apache/public/data/results is a directory


I'm not trying to remove the directory, I'm trying to remove the files in the results directory...

any help would be great!
thanks

Reply With Quote
  #2  
Old April 4th, 2006, 09:31 AM
stdunbar stdunbar is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 1,728 stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level)stdunbar User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 22 h 41 m 16 sec
Reputation Power: 354
Send a message via ICQ to stdunbar Send a message via Yahoo to stdunbar
This seems like the hard way to do it. Why not just use find?

Code:
#!/usr/bin/ksh

xfolder="/serv1/apache/public/data/results"

find $xfolder -atime +0 -exec rm -f {} \;


It basically does the same thing.
Comments on this post
stanleypane agrees: Good call.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.

Reply With Quote
  #3  
Old April 4th, 2006, 09:36 AM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 21
Have you tried just echoing the files found to insure your find command is picking up the correct data?

I ran this same script without the "rm -f" part on an AIX 5.2 server using ksh. Didn't have any problems.

Reply With Quote
  #4  
Old April 4th, 2006, 11:22 AM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 21
I messed with the find command a bit more and noticed that it will include the search directory in your results if the directory fits the atime criteria.

You probably just need to limit your find command to just the files within the directory, i.e.:

Code:

find /searchdir/ -type f -atime +0 -exec rm -f {} \;
Comments on this post
stdunbar agrees: Good catch
hamboy agrees: Totally agree... why didn't I think of that? Thanks

Reply With Quote
  #5  
Old April 4th, 2006, 02:49 PM
hamboy hamboy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 88 hamboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 29 m 18 sec
Reputation Power: 0
Code:
find /temp -atime +3 | grep tmp| while read file
do
rm -f $file
done



how about with grep commands, is there a way to simplify without doing a loop like above?

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Removing Files


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT