Mastodon hachyterm.io

Today I learned that you can pass a date argument to find.

I wanted to delete all files that were older than 10 days using the command line.

We can use find which ships with every Linux distribution.

find . -type f -mtime +20

Find all files that are older than 20 days in the current directory. Now let’s delete them:

find . -type f -mtime +20 -exec rm -f {} \;

I use fd as an alternative to find:

fd -e txt --changed-before 20d -x rm -f {}

Find all files with the extension .txt that are older than 20 days and delete them.

Further Reading