Shell script rm last 1 year file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script rm last 1 year file
# 1  
Old 07-26-2017
Shell script rm last 1 year file

HI
I am using below script to remove only last year files and also need deleted files i want to keep in log file or history for future reference

But it is giving wrong output please help or let me any other way for example 2016 if am using this command it is removing 2016 and 2017 files also

Code:
find . -mtime +365 -exec rm -f {} \;

# 2  
Old 07-26-2017
What happens when you insert "echo" before "rm"? That should give you a dry run of what will be deleted.
# 3  
Old 07-26-2017
or possibly replace rm with ls -l to see the actual dates being selected.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

2. Shell Programming and Scripting

How to pass current year and month in FOR LOOP in UNIX shell scripting?

Hi Team, I have created a script and using FOR LOOP like this and it is working fine. for Month in 201212 201301 201302 201303 do echo "Starting the statistics gathering of $Month partitions " done But in my scripts the " Month " variable is hard-coded. Can you please any one... (3 Replies)
Discussion started by: shoan
3 Replies

3. Shell Programming and Scripting

want to get last year and month from the file

Hi I have files like abc_cd_20110302_123423 abc_cd_ef_20110301_123423 abc_cd_ef_20110403_123423 abc_ef_20110401_123423 I want to extract the the year and month associated with each file. I tried logfileyearmonth=`echo $logfile | awk -F_'{print $NF}'` Any other way can I... (6 Replies)
Discussion started by: dgmm
6 Replies

4. UNIX for Dummies Questions & Answers

Date Script problem for year cross over

Hello, I'm very new to script writing - everything I have I got off the Internet. I'm pretty sure I stole this date script from this site. Anyway, the script works great until I try to obtain a date that falls into last year. I can get 'Dec 31, 2009' but nothing earlier. Below is the... (3 Replies)
Discussion started by: Colel2
3 Replies

5. Shell Programming and Scripting

Add 1 year to System date in script

Hi All, I wanted to add 1 year to the system date in my script. say export start_date=`date +%F` echo $start_date o/p of this is 2009-09-02 To this i want to add 1 year. the output i need here is 2010-09-02 can anybody help me ? Thanks in advance, Vinay (4 Replies)
Discussion started by: vinayakatj56
4 Replies

6. Shell Programming and Scripting

how to read dbf file in shell script and to convert dbf file usinf shell script

Hi all, I am new to shell scripting. I have dbf file and I need to convert it into csv file. OR, can i read the fields from a .dbf file and OR seprate the records in dbf file and put into .csv or txt. Actually in the .dbf files I am getting , the numbers of fields may vary in very record and... (6 Replies)
Discussion started by: gauara
6 Replies

7. Shell Programming and Scripting

Bash Script - Removing Year and Text from File Name

Hi, I have files with names in the following naming pattern, Name.of.moviemoretext-moretext.mov or Name of moviemoretext-moretext.mov And I would like to delete the and moretext-moretext leaving just the Name of movie. The Name of movie will always be different and the year will... (4 Replies)
Discussion started by: Monkey Dean
4 Replies

8. UNIX for Dummies Questions & Answers

Leap year K-shell script

I need a k-shell script that tests for leap-year. Does anyone have one at hand, need ASAP!!! (2 Replies)
Discussion started by: p1jls02
2 Replies

9. Shell Programming and Scripting

shell script to find and copy the files creted in the year 2006 to another directory

Hi All, I am new to UNIX. I will be thankful if some one helps me. I have to write a shell script for one of the requirement. I have files created from Jan 2006 to March 2008. My requirement is to write a script in such a way that 1) To find and copy(not Moving) the files created in the... (2 Replies)
Discussion started by: manas6
2 Replies

10. Shell Programming and Scripting

How do i get the year of the file

When i use, 'ls -ltr' I only see the month and day (timestamp) of the file. How do i see the year also. Thanks and Regards, Ram (1 Reply)
Discussion started by: ramky79
1 Replies
Login or Register to Ask a Question