Visit The New, Modern Unix Linux Community

Delete all instances of a particular file in that month

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete all instances of a particular file in that month
# 1  
Delete all instances of a particular file in that month


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 so can you please let me know .

# 2  
hi Hypesslearner,
Can you please share some input and desire outputs also please refer some example naming convention you are using ?
# 3  
Any attempts from your side? Where are you stuck?
# 4  

Here is the example and what i have tried

I have files getting copied everyday like below


When I m copying this todays file Bkp_20151123160720.tar.gz, files of older dates of 3 days should be removed

I tried below
find Bkp_20151123160720.tar.gz -mtime -3 -exec rm {} \;

wherein I hardcoded the file name which shouldnt be the case .
# 5  
Not sure I understand. You need two commands to remove and copy.
For find, you'll need a starting directory. Try
find /target/path -name "Bkp_*160720.tar.gz" -mtime +3 -exec rm {} \;
cp /source/path/Bkp_*.tar.gz /target/path

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #709
Difficulty: Easy
In Linux, the 'useradd' command is a utility that is used for adding user accounts in Linux and other Unix-like operating systems.
True or False?

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

replacing all instances in a file

Hi I have some script like this: perl -i -p0e 's/"keyword1-.*?"/"keyword2"/s' file to replace some keyword, but it replaces only the first instance of the keyword how can i get it to replace all instances? thanks! (2 Replies)
Discussion started by: vanessafan99
2 Replies

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

4. UNIX for Dummies Questions & Answers

Deleting all instances of a certain character from a text file

In my command prompt I did: sed 's/\://' mytextfile > newtextfile But it only deleted the first instance of : in each line when some lines have multiple : appearing in each one. How can I delete all the : from the entire file? (1 Reply)
Discussion started by: guitarscn
1 Replies

5. Shell Programming and Scripting

How to select only the most frequent instances of a variable string in a file?

I've got a web access file that I want to grep (or awk or perl or whatever will work!) out the most frequent instances of unique IP entries. Meaning the file looks something like this: I'd like to run a sort or grep (or whatever) that will only select out the lines from IP's that had the... (7 Replies)
Discussion started by: kevinmccallum
7 Replies

6. Shell Programming and Scripting

Remove all instances of duplicate records from the file

Hi experts, I am new to scripting. I have a requirement as below. File1: A|123|NAME1 A|123|NAME2 B|123|NAME3 File2: C|123|NAME4 C|123|NAME5 D|123|NAME6 1) I have 2 merge both the files. 2) need to do a sort ( key fields are first and second field) 3) remove all the instances... (3 Replies)
Discussion started by: vukkusila
3 Replies

7. Shell Programming and Scripting

Replacing all instances of an IP address in a log file.

I know this should be simple but the periods in the string replacement are throwing me off. What I want to do is replace in my access.log file with I have tried using 'tr' but its being thrown off by the periods and replacing all sorts of stuff in the file. What do I need... (2 Replies)
Discussion started by: LordJezo
2 Replies

8. UNIX for Dummies Questions & Answers

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... (1 Reply)
Discussion started by: dstinsman
1 Replies

9. UNIX for Dummies Questions & Answers

Multiple file instances

I am capturing text based reports with a specific program, which works no problem. However, since I send report warehouse output as they are migrated from the database software, on occasion when two capture process' initiate simultaneously, the capture file locks up. Is there a way to setup (in... (1 Reply)
Discussion started by: gozer13
1 Replies

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

Featured Tech Videos