09-29-2020, 05:54 AM
#!/bin/bash
## For Finding File and Directory which is older then 30 days
$ find . -mtime +30 -print
## For Finding File and Directory which is older then 30 days in /home/test/Downloads
$ find /home/test/Downloads -mtime +30 -print
## For Deleting those files
$ find <Path_To_Old_Files> -type f -mtime +30 | xargs rm -f
## Or,
$ find <Path_To_Old_Files> -mtime +30 -exec rm -f {} \;
## For Finding File and Directory which is older then 30 days
$ find . -mtime +30 -print
## For Finding File and Directory which is older then 30 days in /home/test/Downloads
$ find /home/test/Downloads -mtime +30 -print
## For Deleting those files
$ find <Path_To_Old_Files> -type f -mtime +30 | xargs rm -f
## Or,
$ find <Path_To_Old_Files> -mtime +30 -exec rm -f {} \;
##Or,
$ find <Path_To_Old_Files> -mtime +30 -delete;