Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

command for deleting log files based on some condition

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-08-2008   -   Original Discussion by pulkit
pulkit pulkit is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 25 February 2008, 4:01 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 01-08-2008   -   Original Discussion by pulkit
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 14 October 2017, 3:52 AM EDT
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
What is the reason to this on your system, or is it homework?

Regards
Sponsored Links
    #3  
Old Unix and Linux 01-09-2008   -   Original Discussion by pulkit
pulkit pulkit is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 25 February 2008, 4:01 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Yes its a kind of assignment...Linux
    #4  
Old Unix and Linux 01-09-2008   -   Original Discussion by pulkit
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 14 October 2017, 3:52 AM EDT
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts
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
Sponsored Links
    #5  
Old Unix and Linux 01-09-2008   -   Original Discussion by pulkit
pulkit pulkit is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 25 February 2008, 4:01 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks in Tons...Linux
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
moving files based on condition awais290 UNIX for Dummies Questions & Answers 14 03-01-2012 04:31 PM
Read 2 files alternatively based on condition. suraj.sheikh Shell Programming and Scripting 3 10-13-2011 04:54 AM
Merging of all files based on a condition arund_01 Shell Programming and Scripting 5 02-15-2010 10:40 AM
How to compare 2 files & get only few columns based on a condition related to both files? reva Shell Programming and Scripting 6 12-10-2009 12:57 AM
Deleting files automatically, the condition in the month of creation FabioALex UNIX for Dummies Questions & Answers 4 12-10-2001 08:14 PM



All times are GMT -4. The time now is 05:27 PM.