How to delete files which more than one Day old?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to delete files which more than one Day old?
# 1  
Old 10-08-2010
Java How to delete files which more than one Day old?

I have a directory /opt/targets which generates more than 1000 files per day and I want to delete all the files which are more than 1 day old...ie 24hrs+
Please help..
# 2  
Old 10-08-2010
try this:

Code:
find . -type f -ctime +1 -exec rm {} \; -print

# 3  
Old 10-08-2010
Quote:
find . -type f -ctime +1 -exec rm {} \; -print
Sorry to be a pain but the above command will give you grief.


Try:
Code:
find /opt/targets -xdev -type f -mtime +1 -print|while read filename
do
       # Remove echo if happy with what will be deleted
       echo rm -f "${filename}"
done


Last edited by methyl; 10-08-2010 at 10:11 PM.. Reason: absolute directory
# 4  
Old 10-11-2010
Thanks a loads..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete records that do not belong to that day

i have a requirement to delete records that do not belong to that day. For example in a file that came on July 31st ,2018 there are records that belong to Aug 1st,2018 as well and I want to find and delete those records. I want to delete anything with 01-Aug-2018. I have several files like that. I... (6 Replies)
Discussion started by: Priya
6 Replies

2. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

3. Shell Programming and Scripting

Delete file to day

friends how I can delete files from a directory for the current date? (2 Replies)
Discussion started by: tricampeon81
2 Replies

4. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

5. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

6. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

7. Shell Programming and Scripting

How to delete subdirectories that are more than 1 day old AND have NO files on them

Hi Experts , At a particular dir , How to delete subirectories that are more than 1 day old AND have NO files in them. PS : -empty option is not working at my Sun OS version. Thanks, A (6 Replies)
Discussion started by: ajaypatil_am
6 Replies

8. Shell Programming and Scripting

Find files of particular day

Hi, I need to find all files of particular day lets say for 2nd august in below. -rw-r--r-- 1 skl eusdc 8168 Aug 5 19:31 aabc123.txt -rw-r--r-- 1 skl eusdc 4251 Aug 5 19:31 aabc124.txt -rw-r--r-- 1 skl eusdc 4252 Aug 6 19:31 aabc125.txt -rw-r--r-- ... (15 Replies)
Discussion started by: sachinkl
15 Replies

9. Shell Programming and Scripting

Not able to delete the files in day wise...

Dear All, I am not able to remove the files in my AIX 5.3 server. My files List /iims-home/data/uat1/batch/staging -rw-r--r-- 1 iims iims 5743 Jun 12 09:04 ErrorReport2008-05-20 09-04-18.doc -rw-r--r-- 1 iims iims 191213683 Jun 12 09:05... (1 Reply)
Discussion started by: bvijaycom
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
Login or Register to Ask a Question