Removing all files older then X days

Log files and output files are automatically generated by applications continuesly. So you will likely have thousands after a few days or weeks of operation. There are multiple ways to remove these older files, but we will demonstrate a simple bash command of

find ./* -mtime +<days> -exec rm {} \;

# Remove files older then 30 days

find ./* -mtime +30 -exec rm {} \;
# Remove files older then 7 days

find ./* -mtime +7 -exec rm {} \;
# Remove files older then 1 hour

find ./* -mtime +1/24 -exec rm {} \;

Leave a Reply