I have a directory with a few TB of files. I'd like to delete every file in it that is older than 14 days.
I thought I would use find . -mtime +13 -delete
. To make sure the command works as expected I ran find . -mtime +13 -exec /bin/ls -lh '{}' \; | grep '<today>'
. The latter should return nothing, since files that were created/modified today should not be found by find
using -mtime +13
. To my surprise, however, find
just spew out a list of all the files modified/created today!
The switch -type f means we want to look for files only. The -mmin stands for the modification time, and +15 means we want files that were last modified 15 minutes ago or earlier. The action flag -delete asks find to delete all the files it finds.
To delete files older than 10 days in Windows 11 or Windows 10, you can use the ForFiles command. First, open the Command Prompt with administrator rights. Then, enter this command: ForFiles /p “folder-path” /s /d -10 /c “cmd /c del /q @file”. It will remove all the files older than 10 days only.
Your command will look at the top level directory /var/log/mbackups and also descend into any subdirectories, deleting files that match the seven day criterion. It will not delete the directories themselves. For files older than 7 days, you need -mtime +6 (or '(' -mtime 7 -o -mtime +7 ')' ), not -mtime +7 .
find your/folder -type f -mtime +13 -exec rm {} \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With