LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-26-2014, 10:42 PM   #1
vamsimak2000
LQ Newbie
 
Registered: Nov 2014
Posts: 2

Rep: Reputation: Disabled
Please help me how to delete the files in one folder which are more than 60 days old


Hi I know how to delete the files the files which are morethan 60 days old. But i have to satisfy below conditions. pls help me to get correct script to automate this.

I have below files for each day on monthly basis. So i have these files for last 3 years.

vtm_data_12month_20140301.txt vtm_data_12month_20140301.control vtm_mtd_20130622.txt vtm_mtd_20130622.control vtm_ytd_20131031.txt vtm_ytd_20131031.control

I'd like to write a script find the all files which are more than 60 days old and delete them all but except last month file. suppose for january i want to keep the last file(latest)vtm_data_12month_20140131.txt and delete all 30 files. Issue here is there is chance that i might have files received for january 30th so in that case i should not delete the latest file but i have to delete the rest..

please advice me how can we achieve this via shell script. your response is highly appreciated.
 
Old 11-26-2014, 11:12 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
The find command can do what you want.
Code:
find /path/to/files/ -mtime +60 -exec rm {} \;
Check the man page to see all the options for the find command.
 
Old 11-27-2014, 03:43 AM   #3
vamsimak2000
LQ Newbie
 
Registered: Nov 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
That doesnt answer my question

Hi Sorry. Please read My requirement.
 
Old 11-27-2014, 04:01 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
the response was not [highly] appreciated..... What is the problem with that solution?
 
  


Reply



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
delete files when it's older 30 days Madison00 Linux - Newbie 8 01-07-2011 02:07 AM
[SOLVED] Delete old files older than 7 days anon091 Linux - Newbie 3 09-18-2009 01:15 PM
Automated script to DELETE files older than 2 days in a Particular folder siddhartha_ece2004 Linux - Newbie 14 07-11-2008 05:46 AM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 03:43 PM
bash: delete files older than 7 days in a folder and subfoldes lupomanaro Programming 1 05-07-2008 10:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 06:51 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration