Delete files older than today


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete files older than today
# 1  
Old 12-11-2009
Delete files older than today

is it -mtime +1 as i need all files older than today to be deleted
# 2  
Old 12-11-2009
why don't you try it out ?
# 3  
Old 12-11-2009
yes that should work..
before deleting confirm the file list...
Code:
find . -mtime +1 -ls -long;

# 4  
Old 12-11-2009
find . -type f -mtime +1 -print

it shows older than 1 day i need all except for today
# 5  
Old 12-11-2009
Quote:
Originally Posted by dinjo_jo
find . -type f -mtime +1 -print

it shows older than 1 day i need all except for today
that means the same thing unless your looking for 00:00 boundaries. if you have GNU find look at the -daystart and -newer options. this might work for what you need.

Last edited by frank_rizzo; 12-11-2009 at 02:38 AM.. Reason: added GNU find comment
# 6  
Old 12-11-2009
Quote:
Originally Posted by frank_rizzo
that means the same thing unless your looking for 00:00 boundaries. if you have GNU find look at the -daystart and -newer options. this might work for what you need.
If that is the case, try

Code:
ls -l | grep  -v "$(date +"%b %d")" | awk '/^-/{ print $NF }' | xargs rm -i -

# 7  
Old 12-11-2009
GNU find supports the -daystart option, which starts comparing against the change of date (00:00). Or, for compatibility, you can use -newer with some boolean logic:
Code:
touch -t $( date +%Y%m%d000000 ) today
find /path ! -newer today

will find anything not newer than today midnight.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to delete all the files older than a date?

Hi, I need a command for deleting all the compress files *.Z that are older than the current date - 5 days. Basically I have a directory where daily I meet some back up files and I want to remove automatically the ones 5 days (or more) older than the current date. How can I write a 'rm' command... (1 Reply)
Discussion started by: Francy
1 Replies

2. Shell Programming and Scripting

Delete files older than X days.

Hi All, I am using below code to delete files older than 2 days. In case if there are no files, I should log an error saying no files to delete. Please let me know, How I can achive this. find /path/*.xml -mtime +2 Thanks and Regards Nagaraja. (3 Replies)
Discussion started by: Nagaraja Akkiva
3 Replies

3. Shell Programming and Scripting

To delete files older than 24 hrs

I have to retain only 1 day files in my system an I have to delete all the other files which are older than 24 hrs. Please let me know the option I have to give in the find -mtime command. (3 Replies)
Discussion started by: rajesh8s
3 Replies

4. Solaris

Delete files older than 30 days

Hi all, I want to delete log files with extension .log which are older than 30 days. How to delete those files? Operating system -- Sun solaris 10 Your input is highly appreciated. Thanks in advance. Regards, Williams (2 Replies)
Discussion started by: William1482
2 Replies

5. Shell Programming and Scripting

Find files older then today & display with timestamp info

Small query- I want to do some operation on all the files older then today. Before I do that operation, i want to verify if the command works properly or not. Surprisingly, the command below returns me file, which are created today - find /mrk_archive/PG/ftp/incomming/gbs/2008 -type f... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

6. Shell Programming and Scripting

delete files more than 15 days older

i have to delete files which are older than 15 days or more except the ones in the directory Current and also *.sh files i have found the command for files 15 days or more older find . -type f -mtime +15 -exec ls -ltr {} \; but how to implement the logic to avoid directory Current and also... (3 Replies)
Discussion started by: ali560045
3 Replies

7. UNIX for Dummies Questions & Answers

Delete files older than 30 days

This is driving me crazy. How can I delete files in a specifc directory that are over 30 days old? Thanks in advance. (3 Replies)
Discussion started by: tlphillips
3 Replies

8. UNIX for Dummies Questions & Answers

How can I delete files older than 7 days?

I will like to write a script that delete all files that are older than 7 days in a directory and it's subdirectories. Can any one help me out witht the magic command or script? Thanks in advance, Odogboly98:confused: (3 Replies)
Discussion started by: odogbolu98
3 Replies

9. UNIX for Dummies Questions & Answers

delete files older than 7 days

can anyone tell me how I would write a script in ksh on AIX that will delete files in a directory older than 7 days? (1 Reply)
Discussion started by: lesstjm
1 Replies
Login or Register to Ask a Question