# Delete files based on date



## apsf68 (Sep 21, 2010)

Hi,

I'm new with FreeBSD and I need to delete files based on there date.
I think this is possible but I don't know how to do it.
Can someone please help me?
Thanks.

Paulo Ferreira


----------



## bsm (Sep 21, 2010)

Hi

You can use the find command for this (man find) and use the -mtime -ctime or -atime together with the -delete options

For example find files which are not modified within the last 10 days in /home
[CMD="find /home -mtime +10 -delete"][/CMD]

Be careful! It's advisable to first produce a list to examine the results and get familiar with the find command.


----------



## User23 (Sep 21, 2010)

If you only need to delete files that are older than x minutes you can use "find" for that job.

Example: find all files in /usr/home/foobar owned by foobar that are older than 1051200 minutes (2 years) and delete them.


```
find /usr/home/foobar -user foobar -type f -mmin +1051200 -delete
```

or you write a script that fit your needs.


----------



## apsf68 (Sep 21, 2010)

Thanks.
That's exactly what I need.


----------



## DutchDaemon (Sep 21, 2010)

You don't need to convert everything into minutes; find(1) understands smhdw flags (seconds, minutes, hours, days, weeks) etc. as well, e.g. [cmd=]find / -type f -name "*something*" -mtime +2d[/cmd]


----------

