Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete files by modified date

Status
Not open for further replies.

hcclnoodles

IS-IT--Management
Jun 3, 2004
123
GB
Hi, im sure this is a simple question but I have a director y with thousands of files in it (all randomly named and all created ant differnet times),

I would like to find a way of deleting all of the files that were created before 22 November (which is the majority of them) without having to individually paste each one into a "rm" command

Is there a way I can delete using the unix modified date as a parameter ??
 
find <path to dir> -mtime +4 (for example) | xargs rm

Be careful, and test using xargs ls first to check you're hitting the correct files. HTH.
 
i presume "-mtime + 4" is todays date minus 4 days ?
 
find <path to dir> -mtime +4 (for example) | xargs rm

Be careful, and test using xargs ls first to check you're hitting the correct files. HTH.
 
man find
man touch

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sorry about the double posting - these seem to be happening regularly these days. See PHV's post, but yes, mtime is todays date (and time when the command is issued) minus 4 days. As I said, using ls first will clarify exactly which files you are about to delete.
 
You could also look at the directory and find a filename (or create one with touch -t) and delete every file older than that filename with:
find /path/to/dir ! -newer /path/to/dir/filename | xargs rm

Note that /path/to/dir/filename is also deleted as it is not newer that itself.

I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top