Delete Files Older Than 30 Days
This command will delete all files older than 30 days in system /opt/backup directory.
find /opt/backup -type f -mtime +30 -exec rm -f {} \;
If you want to just perform the action in your current directory, use ‘.’ as the folder name. e.g.
find . -type f -mtime +30 -exec rm -f {} \;
If you want to change the number of days, just change the +30 to another number. e.g. +7 or +14
Delete Files Older Than 30 Days with .jpg Extension
If you want to delete only specified extension files, you can use the following command.
find /var/log -name "*.jpg" -type f -mtime +30 -exec rm -f {} \;
Above command will delete only files having .jpg extension.
Delete files older than 30 days in Linux