Find files that are created more than 7 days and delete them using bash
Filed Under (linux) by admin on 18-01-2012
Here we will use the find -mtime and xargs commands
Complete script:
find '/home/user/data/' -name '*.txt' -mtime +7 | xargs rm
Explanation:
find -mtime displays files made based on given number of days
find '/home/user/data/' -name '*.txt' -mtime +7
xargs captures the result of a previous command and pass it as an argument for another function
find '/home/user/data/' -name '*.txt' -mtime +7 | xargs rm
The result of the find command is passed to another function rm which then removes the files


