Detete File greather Than 12 Months


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Detete File greather Than 12 Months
# 1  
Old 12-23-2008
Detete File greather Than 12 Months

Hi All,

I have a temporary file which will appended with some records daily. After 12 months, i need to delete the old file and start the new file.

Can any one help me how to delete the file which having creation date more than 12 months?

I have a MonthYear in the name of the file. I extracted that part and compared with Current monthYear and tried to find the difference, but it is not giving the result as expected.

Can any one help me on this?

-- Raam.
# 2  
Old 12-23-2008
use find utility with mtime option then pass those files thru exec command to delete/move as follows,

find . -mtime +<time> -type f -exec rm -rf {} \;

NOTE instead of option -type you can use option -name and context/pattern of your file name.

Last edited by manas_ranjan; 12-23-2008 at 12:48 PM.. Reason: added NOTE
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove lines where field count is greather than 1 in two fields

I am trying to remove all the lines and spaces where the count in $4 or $5 is greater than 1 (more than 1 letter). The file and the output are tab-delimited. Thank you :). file X 5811530 . G C NLGN4X 17 10544696 . GA G MYH3 9 96439004 . C ... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

3. UNIX for Dummies Questions & Answers

single line command to delete a 6 months old file

i had this scenario where i need to delete a file that is 6 months old which is no longer needed. basically the filename is in the format of PCARDDAILYmmddyyyy.txt where the mm is the month, dd is the day, and yyyy is the year. e.g. PCARDDAILY05262009.txt PCARDDAILY05252009.txt ... (6 Replies)
Discussion started by: wtolentino
6 Replies

4. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

5. Shell Programming and Scripting

calculate 13 months ago

hi, I have a big file that contains datas since 4 years ago. I need re-create this file but just lines that are 13 months ago from today. see what I have: ( I have a file.ksh that calls this file.scl ok !!) ======== file.scl ================ /STATISTICS=stderr /STABLE /NODUPLICATES... (4 Replies)
Discussion started by: andrea_mussap
4 Replies

6. UNIX for Advanced & Expert Users

Subtract 2 months from the date

I have the script which appends month and year to the name of the file. Now every time when I append the month-year combination I have to subtract 2 months from the current date and then append it, since we are sending our vendor 2 months prior worth of data eveytime. #! /usr/bin/ksh ... (5 Replies)
Discussion started by: mahekr2000
5 Replies

7. Shell Programming and Scripting

some months ego

Hi, how can I format date function to find n (n=1 to 11) months ego ? For exemple now we are in july and I want to have a variable presenting april. How should it be : month=`date +%b`????? Many thanks before. (8 Replies)
Discussion started by: big123456
8 Replies

8. UNIX for Advanced & Expert Users

Comparing two months

Hi all, Using shell script and awk statements, I manage to get the month and year of the Patch Bundle installed on the system. Now I have to compare month and year of Patch Bundle installed to the Patch Bundle which is desired on the workstation. I am able to do easily comparison of year but not... (1 Reply)
Discussion started by: pankschawla
1 Replies

9. IP Networking

DNS Help - Been trying to do this for months

Ok someone has to be able to help me here. I have the latest webmin, and i have bind i have a domain name called thedigitaldream.co.uk i have one server, just one as im poor so the one server is gunna be the dns, email, web and ftp server. Its only for a small site anyway so it will... (16 Replies)
Discussion started by: matt2kjones
16 Replies
Login or Register to Ask a Question