LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Delete files for a particular changed date recursively? (https://www.linuxquestions.org/questions/linux-newbie-8/delete-files-for-a-particular-changed-date-recursively-186860/)

qwertyme 05-28-2004 05:29 AM

Delete files for a particular changed date recursively?
 
Hi there!

newbie here needs help.
your help will be much appreciated.

How do I delete files that have a particular changed dated recursively?
What is the command? can i use rm?

Thanks in advance

Regards

Demonbane 05-28-2004 05:31 AM

you can probably write a very simple script using "find" and "rm"

qwertyme 05-28-2004 05:56 AM

Hi Demonbane,

i have tried going through the man pages for FIND, but i still can't figure out to use it to find files that are last changed on a particular date.

And after i am able to get a list of the files, how do i pipe it to RM to remove it?

Sorry, i am really not familiar with this.


Regards

Demonbane 05-28-2004 06:09 AM

Well for example if the files were modified 3 days ago you can probably use something like this:
Code:

find . -mtime 3 -exec rm -i \{\} \;

emrecio 01-23-2009 09:49 AM

Quote:

Originally Posted by Demonbane (Post 958863)
Well for example if the files were modified 3 days ago you can probably use something like this:
Code:

find . -mtime 3 -exec rm -i \{\} \;

What if the files you're looking for were modified on a particular date 10 years ago? Is there another way of determining the #of days or something similar instead of counting it all in your head (assuming you can remember leap years and seconds).

emrecio 01-23-2009 10:41 AM

daysago.php, daysago.sh
 
The following PHP script kinda does the trick

Code:

#!/usr/bin/php
<?php

if ($argc > 1) {
        $from = strtotime($argv[1]);
}  else {
        echo "Must supply date. (i.e.: 2006-01-12 22:45:00)\n";
        exit (1);
}

$to = time();

$current = $to - $from;

echo $current / 60 / 60 / 24 , " days ago\n";

?>

Or just

Code:

#!/bin/bash
#

if [ -z "${1}" ]; then
        echo "Must enter a date (i.e.: 2009-01-01 22:45:35)"
        exit 127
fi

FROM=`date +%s -d ${1}`
TO=`date +%s`

DIFF_SEC=$((TO - FROM))
DIFF_DAYS=$((DIFF_SEC / 60 / 60 / 24))

echo "$DIFF_DAYS days ago."



All times are GMT -5. The time now is 12:18 PM.