Bash Scripting: Delete Files of a Certain Age

Last Updated on

For server maintenance it can be useful to run scheduled jobs to clean up various directories;  user generated files and system logs that aren’t automatically maintained can become massive disk hogs over time.  This simple line of code will delete any file older than 19 days in the specified directory.

1
find /media/usb_drive2/incoming* -mtime +19 -exec rm {} \;
Lima

About the author

Lima is the visual nautical indicator for "stop instantly."

Leave a Reply