We can do it using this command
find /path/to/files* -mtime +365 -exec rm {} \;
How it works..
/path/to/files*
is the path to the files to be deleted.
-mtime
is used to specify the number of days old that the file is. +365 will find files older than 365 days which is one year.
-exec
allows you to pass in a command such as rm.
You can also do it using below command:
If you are deleting files older than 1 year
find /path/to/files* -mtime +365 -delete
If you are deleting files older than 6 month
find /path/to/files* -mtime +182 -delete
If you are deleting files older than 1 month
find /path/to/files* -mtime +30 -delete
If you are deleting files older than 7 days
find /path/to/files* -mtime +7 -delete
Great post! Thak you! Here is another option. Specify the date from which we want to delete the files:
find /SYSADMIT/* -type f -not -newermt “AAAA:MM:DD HH:MI:SS” -delete
Extracted from: https://www.sysadmit.com/2019/08/linux-borrar-ficheros-por-fecha.html