Delete command
find /path/to/files/ -type f -name '*.csv' -mtime +30 -exec rm {} \;
Explanation
- First part is the path where your files are located. Don’t use wildcard * if you have a lot of files because you will get Argument list too long error.
- Second part -type is the file type f stands for files
- Third part -name is limiting *,csv files
- Fourth part -mtime gets how many days the files older then will be listed. +30 is for files older then 30 days.
- Fifth part -exec executes a command. In this case rm is the command, {} gets the filelist and \; closes the command
Move command
find /path/to/files/ -type f -name '*.csv' -mtime +30 -exec mv {} /path/to/archive/ \;
Explanation
- First part is the path where your files are located. Don’t use wildcard * if you have a lot of files because you will get Argument list too long error.
- Second part -type is the file type f stands for files
- Third part -name is limiting *,csv files
- Fourth part -mtime gets how many days the files older then will be listed. +30 is for files older then 30 days.
- Fifth part -exec executes a command. In this case mv is the command, {} gets the filelist, path where to move the files and \; closes the command