Find files on Linux with find

Finding files on Linux is pretty simple, I was in the middle of creating a bash script when I was in need to find files inside a certain folder that was older than X amount of days.

Syntax:
find $PWD -type f -mtime +10

This tells find to search the current directory for files including hidden files that have been last modified within 10 days.  To take this a step farther we can now invoke a second part to delete all the files that are older than the last 10 days.

Syntax:
find $PWD -type f -mtime +10 -exec rm {} \;

We added an -exec rm {} \; which tells find to DELETE all the results it finds, this can help if you have a script that backs up tar files, database backups, or anything really, as a matter of fact find can do alot more stuff than just what was mentioned but if you want to see more just man find.

Tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.