Delete filename with month -2


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete filename with month -2
# 1  
Old 02-14-2006
Delete filename with month -2

KSH - I've got a script that is generating a number of log files like this:

y=`date +"%y"`
m=`date +"%m"`

$LOG_DIR/tuscprof_tbl_$y$m.log

I only want to keep the current 2 months' worth of files (current month and prior month). So I'm trying to come up with a way to delete any that contains a filename month that is -2 from current month.

I thought I could do it like this, but it's not working:

if [[ -e $LOG_DIR/*_$(($y))*.log && -e $LOG_DIR/*_*$(($m - 2)).log ]]
then rm $LOG_DIR/*_*$(($m - 2)).log
fi

if [[ -e $LOG_DIR/*_$(($y - 1))%*.log && ! $m -eq 01 ]]
then rm $LOG_DIR/*_$(($y - 1))%*.log
fi
# 2  
Old 02-14-2006
find $LOG_DIR -name 'tuscprof_tbl_*.log' -mtime +60 -exec rm -f {} \;
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Hadoop directories delete older than a month

-bash-4.1$ hdfs dfs -ls -R /data/backup/prd/xyz/ | grep '^d' drwxr-xr-x - abisox abadmgrp 0 2018-05-05 01:03 /data/backup/prd/xyz/20180301 drwxr-xr-x - abisox abadmgrp 0 2018-05-05 01:03 /data/backup/prd/xyz/20180302 drwxr-xr-x - abisox abadmgrp 0 2018-05-05 01:03... (2 Replies)
Discussion started by: himanshupant
2 Replies

2. Shell Programming and Scripting

Delete all instances of a particular file in that month

Hi I need to move one file from source path to target path .Before moving , I need to go to target path and delete the files having certain naming convention in that particular month . So at any point of time while moving i should have only one file . Is there any command that can do this if... (4 Replies)
Discussion started by: Hypesslearner
4 Replies

3. UNIX for Dummies Questions & Answers

Create file with last month in filename

Hi, I have a bash script which outputs a file with current year and month in the filename. Last line is: cat result_* > output.$(date +%y%m) So for Feb 2013 this gives me output.1302 Now I am requested to run the script every first day of the month, but with the previous month in... (4 Replies)
Discussion started by: viscacha
4 Replies

4. Shell Programming and Scripting

Adding Previous Month To Filename

Dear experts, I'm using solaris 5.10 and bash. I want to zip file "Amount.txt" to "Amount.zip" and rename it to "Amount_<prev_month>_<this year>.zip". For example, file for this month should be renamed to "Amount_06_2012.zip", for next month it should be "Amount_07_2012.zip". I have no problem... (8 Replies)
Discussion started by: kris.adrianto
8 Replies

5. Shell Programming and Scripting

Delete files based on specific MMDDYYYY pattern in filename

Hi Unix gurus, I am trying to remove the filenames based on MMDDYYYY in the physical name as such so that the directory always has the recent 3 files based on MMDDYYYY. "HHMM" is just dummy in this case. You wont have two files with different HHMM on the same day. For example in a... (4 Replies)
Discussion started by: shankar1dada
4 Replies

6. Shell Programming and Scripting

Delete duplicate data and pertain the latest month data.

Hi I have a file with following records It contains three months of data, some data is duplicated,i need to access the latest data from the duplicate ones. for e.g; i have foll data "200","0","","11722","-63","","","","11722","JUL","09" "200","0","","11722","-63","","","","11722","JUL","09"... (10 Replies)
Discussion started by: vee_789
10 Replies

7. Shell Programming and Scripting

Script to delete text from the end of a filename

Hi all, I am trying to write a script that will delete a certain amount of text from the end of a filename. For example. Input: name of file (more text).pdf Output: name of file.pdf So is it possible to write a script the deletes, in this example twelve (12) digits from the end... (6 Replies)
Discussion started by: Monkey Dean
6 Replies

8. Shell Programming and Scripting

delete numbers in a filename

I have some files where numbers are part of like eg 1add1.txt 23sub41.txt etc I want to remove numbers from the filenames(whereever it may be). I used echo `ls *.txt | sed -e "s///"` But its removing first digits like 1add1.txt becomes add1.txt My intention is to make 1add1.txt... (3 Replies)
Discussion started by: villain41
3 Replies

9. Shell Programming and Scripting

delete files one day old in current month only

i want to delete files that are one day old condition is files should be of current month only ie if iam running script on 1 march it should not delete files of 28 feb(29 if leap year :-)} any modifications to find $DIR -type f -atime +1 -exec rm -f{}\; (4 Replies)
Discussion started by: maverick
4 Replies

10. UNIX for Dummies Questions & Answers

Stupid filename - can't delete it

I have created a file with a stupid filename with a perl script, and now I can't delete it. The file's called -s-c.log. When I try to delete it, I get that: <>/home/ahi $ rm -s-c.log UX:rm: ERROR: Illegal option -- s UX:rm: ERROR: Illegal option -- - UX:rm: ERROR: Illegal option -- c UX:rm:... (4 Replies)
Discussion started by: sTorm
4 Replies
Login or Register to Ask a Question