I'm trying to delete all files and folders in the /tmp
dir that are older than a day.
I know to delete all the files and folders I have to do
rm -rf *
But I'm unsure how else I find all the files and folders older than a day to delete those and put the cron in.
First, use
find
to select these files:will find files that were modified more than 1440 minutes ago. (There is an option to use days instead of minutes, but it rounds upwards and +1 will mean 2 days or more, unfortunately. See notice below).
Try this, and if you are satisfied that this finds the right files, delete them in one go:
See
man find
for other possibilities (last status changed time, access time).Notice on the usage of
-mtime +1
:In other words,
-mtime
can count only in units of 24 hours or one day each so as far as-mtime +1
goes, this means exactly more than one day by at least one day ( ie. two days+ )-mmin
on the other hand can count in minutes. So, if strict accuracy is vital, then-mmin +1440
( 1440 minutes = 1 day ) could be used instead of-mtime +1