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 file older than 5 days

Status
Not open for further replies.

newhandle

Technical User
Aug 28, 2001
2
AU
What is the command to delete files older than 5 days ?

Thanks.
 
Hi newhandle,

you can use find for this:

find <directory to delete from> -mtime +5 -exec rm {} \;

Be careful with this - it deletes everything not modified for 5 days or more in the specified directory. It's always as well to do a:

find <directory to delete from> -mtime +5 -print

first, just to check that the files returned are indeed the ones you want. If not, it's possible the specify certain files like:

find <directory to delete from> -name '*.txt' -mtime +5 -exec rm {} \;

Replace *.txt with whatever filename/extension combination you require.

Hope this helps.

 
You also have the -atime & -ctime options

atime = access time
ctime = inode updated during the last 24 hrs

Regards --
| Mike Nixon
| Unix Admin
| ----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top