Deleting the files comparing the creation dates


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting the files comparing the creation dates
# 1  
Old 04-10-2008
Data Deleting the files comparing the creation dates

Hi Gurus,

I am new to unix.
I have a requirement where i need to delete some files in a folder twice a week.
Suppose i have a folder AAA. In that i have files from 01/04/2008 to 10/04/2008

I want to remove all the files except last 3 days i.e., 10,9th & 8th.

Every week twice we want to remove the files.

Please guide with an example to solve the issue.

Thanks & Regards,
Sandeep
# 2  
Old 04-10-2008
To remove 3 days old files

find . -name '*' -mtime -3 -exec rm {} \;
# 3  
Old 04-10-2008
Code:
find /AAA -mtime +3

will give you all files in directory (and sub-directories) that are more than 3 days old. If you wanted to delete them you could add

Code:
find /AAA -mtime +3 -exec rm {} \;

which may, or may not depending on your version of rm (and any aliases set up), ask you whether to delete each and every file.

To not be asked change the
Code:
rm {} \;

to be
Code:
rm -f {} \;

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting the files between particular dates

Hi Please help me for the below task. In my home directory if I run ls -l command, it lists all the files, here I want to delete files created from January 2014 to Aug 2014...but I need to keep the files which are created after September 01 2014. Thanks Siva (3 Replies)
Discussion started by: kumar85shiv
3 Replies

2. Shell Programming and Scripting

Comparing Dates

Hi I'm trying to compare the current date (dd-Mmm-yyyy) against a variable that is an extracted date from an sql script. Below is the code: datenow=`date '+%d-%h-%Y'` #datenow is the current date in the format dd-Mmm-yyyy sqlplus $dbuserid/$dbpassword @ $SCRIPT_PATH/business-date.sql >... (3 Replies)
Discussion started by: joyAV
3 Replies

3. Shell Programming and Scripting

Comparing dates

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing.One more condition is change of year also i.e today is Jan1 2012 and yesterday is Dec 31 2011. The above rek i want in Shell... (4 Replies)
Discussion started by: kumarmsk1331
4 Replies

4. Shell Programming and Scripting

Need help comparing two files and deleting some things in those files!

So I have two files: File1 pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2 pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2 ref4948 1.1 treehouse.txt 1.6 ref8573 1.5 ref3284 1.4 ref5838... (24 Replies)
Discussion started by: linuxkid
24 Replies

5. Shell Programming and Scripting

Comparing the modified dates of files in two directories

Hi Is it possible to compare the modified dates of all the files in two directories using shell script? I would like to take a backup of a directory in production server regularly. Instead of copying all the files in the directory, is it possible to list only the files that are... (2 Replies)
Discussion started by: ashok.k
2 Replies

6. UNIX for Advanced & Expert Users

deleting files after the creation of a tar archive

Hi, I would modify to delete the files after creating the tar archive. How I can modify the following command: tar -cvvf logswitch.tar `find *.log* -mtime +5` It create a tar with files that are older than 5 days. (5 Replies)
Discussion started by: Minguccio75
5 Replies

7. UNIX for Dummies Questions & Answers

deleting files with dates 3 months ago

please help me with this????? :confused: :confused: i need to create a program that will run in unix that will delete all files in a given directory that is at least 3 months old. first the program will need to automatically know what date it is right now to determine the files it will... (3 Replies)
Discussion started by: godalle
3 Replies

8. Programming

comparing dates

hi is there a c function in linux for comparing dates. thanx in advance. svh (2 Replies)
Discussion started by: svh
2 Replies

9. Shell Programming and Scripting

comparing 2 dates

hi , I have two variables both containg dates, x= `date` and y= `date' their format being -> Fri Nov 12 22:59:50 MST 2004 how do I compare which one is greater. ->Can dates be converted into integer and then compared? ( one lengthy way would be to compare the words one by... (7 Replies)
Discussion started by: k_oops9
7 Replies

10. UNIX for Dummies Questions & Answers

Deleting files automatically, the condition in the month of creation

Hi all, I'm newby in this great forum. I'm working as an Intelligent Networks Administrator for a Fixed telephony company. I want to write a script shell that helps me in my daily/weekly tasks. A voice switch sends every hour a statistic file to a log directory. By now, i've got more than 5000... (4 Replies)
Discussion started by: FabioALex
4 Replies
Login or Register to Ask a Question