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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting files based on file name and modified time ammu UNIX for Dummies Questions & Answers 1 01-22-2008 08:09 AM
Traversing thru dirs and deleting files based on date ravi2082 Shell Programming and Scripting 5 07-18-2007 01:28 PM
Read file based on condition sbasetty Shell Programming and Scripting 5 01-31-2007 11:54 PM
Deleting files with zero length using ls command GNMIKE UNIX for Dummies Questions & Answers 6 07-10-2005 04:34 AM
Deleting files automatically, the condition in the month of creation FabioALex UNIX for Dummies Questions & Answers 4 12-10-2001 05:14 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-08-2008
Registered User
 

Join Date: Jan 2008
Posts: 8
command for deleting log files based on some condition

Hello,

Can anyone pls. provide me with the command for deleting files older then 15 days with a restriction to keep at least 5 files in a directory even if they are older then 15 days.

Any help will be highly appreciated.

Thanks,
Pulkit
Reply With Quote
Forum Sponsor
  #2  
Old 01-08-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,292
What is the reason to this on your system, or is it homework?

Regards
Reply With Quote
  #3  
Old 01-09-2008
Registered User
 

Join Date: Jan 2008
Posts: 8
Yes its a kind of assignment...
Reply With Quote
  #4  
Old 01-09-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,292
Ok, some hints:

To find older files you can use the find command with the -mtime option.
To keep 5 files of the selection you can pipe the result to awk, to ignore the first 5 files you can do something like:

Code:
awk 'NR<6{next}{print}'
So it should look like:

Code:
find <options> | awk '....' | rm -f
If you have many files you can use xargs.

Code:
...| xargs rm -f
Check the man page of find for the options, search on this forum or Google for examples.


Regards
Reply With Quote
  #5  
Old 01-09-2008
Registered User
 

Join Date: Jan 2008
Posts: 8
Thanks in Tons...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0