Bash Scripting: Delete Files of a Certain Age

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.

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

About the author

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

Leave a Reply