Summary: Removing files based on the date

From: Sue Chichester (
Date: Mon Jan 29 1996 - 08:50:20 CST

Thanks everyone. Once again, you guys were great! I guess I didn't think
of find. Here's a couple of the first replies I received. BTW - It worked

Thanks - Brad Young

   Take a look at the man pages for find; especially look at
find . -newer, or , in your case, find . ! -newer. Be very careful not
to delete any files that you really don't want to remove.

  find . ! -newer <> -ls

before you do

  find . ! -newer <> -exec /bin/rm {} \;

Thanks Sean Ward

find / -mtime +2 -exec rm -f {} \;

The "-mtime +2" part tells find to list only the files that were modified more
than 2 days ago, and the exec part does the removal. The curly braces are a
placeholder (so to speak) for the output from the mtime, and the "\;" is
necessary in find (don't know why).

I would also recommend doing this at night, as the find command is fairly cpu
Thanks Greg Harrison can use something like

find / -mtime +4 -exec rm {}\:

That will remove any file that hasnt been modified in more than 4 days.
You can also use
        atime = access time
        ctime = creation time

I like to use it in conjunction with print to keep a record of what was deleted.
Something like..
        find / -ctime +4 -print -exec rm {} \; > /tmp/deleted.log
Anyway, check out the man on find to see what flags you can use to get the
job done.


> I'm running Solaris 2.4. Is there a UNIX command to remove files based on
> their age. I can't seem to find anything. I want to remove every file
> that was created before January 23rd, 1996 for example.
> This has to do with a system running a news server that must have had it's
> expire go wrong at sometime. I'm finding alot of old articles that weren't
> deleted.

Sue Chichester
SUNY Geneseo Asst. Director, Systems, Networking & Operations
South Hall 124B2 email:
1 College Cirle Phone: (716) 245-5577
Geneseo, NY 14454 FAX: (716) 245-5579

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:52 CDT