LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-28-2004, 05:29 AM   #1
qwertyme
LQ Newbie
 
Registered: May 2004
Posts: 2

Rep: Reputation: 0
Question 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
 
Old 05-28-2004, 05:31 AM   #2
Demonbane
Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
you can probably write a very simple script using "find" and "rm"
 
Old 05-28-2004, 05:56 AM   #3
qwertyme
LQ Newbie
 
Registered: May 2004
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
Old 05-28-2004, 06:09 AM   #4
Demonbane
Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
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 \{\} \;
 
Old 01-23-2009, 09:49 AM   #5
emrecio
LQ Newbie
 
Registered: Nov 2005
Location: Seattle, WA, US
Distribution: Fedora
Posts: 12

Rep: Reputation: 0
Unhappy

Quote:
Originally Posted by Demonbane View Post
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).
 
Old 01-23-2009, 10:41 AM   #6
emrecio
LQ Newbie
 
Registered: Nov 2005
Location: Seattle, WA, US
Distribution: Fedora
Posts: 12

Rep: Reputation: 0
Lightbulb 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."
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete/move/copy files of specific date imsajjadali Red Hat 26 11-07-2013 11:34 PM
Recursively move files michaelsanford Linux - General 4 10-02-2005 01:50 PM
Delete files based on date stefaandk Linux - General 3 06-17-2005 02:20 AM
delete files date wise hardeep_ubhi Linux - General 1 11-16-2004 02:07 AM
How to delete the first line of evrer .java file recursively ththomas Programming 2 03-08-2004 08:55 AM


All times are GMT -5. The time now is 03:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration