find . -type f -mtime +0 -exec rm -f {} +
or
find . -type f ! -mtime -1 -exec rm -f {} +
Would remove the regular files whose content has been last modified more than 24 hours ago (-mtime +0
meaning: whose age in days (rounded down to an integer, days are 24 hours, or 86400 Unix epoch second duration) is strictly greater than 0).
Some find
implementations have a -delete
predicate which you can use in place of -exec rm -f {} +
which would make it safer and more efficient.
For files that have been last modified earlier than today 00:00:00, with GNU find
, you can add the -daystart
predicate. That will include the files that were last modified yesterday even if less than 24 hours ago.
With some find
implementations, you can also do:
find . ! -newermt 00:00:00 -delete
To delete files that have been last modified before (or at exactly) 00:00:00 today.
ext4
andbtrfs
as far as I know.-mtime
gives the last time that the file was modified in any way including the contents, ownership, permissions, and name changes so neither your command nor those in the answers will delete files which weren't created today. It will delete files which weren't modified today.