Sometimes we schedule a particular daily job in cron, which generates daily log files. Though the size is smaller, we can't keep those files. In that case we need a shell command to clean up and here it is:
To delete all the files whose data modified before 'n' days:
find -mtime +n -delete
To delete all the files whose data modified in last 'n' days:
find -mtime -n -delete
To delete files of a particular patterns, say 'archive_date.csv'
find -name 'archive_*.csv' -mtime +n -delete
To list out all files older than 'n' days along with date and time, just like 'ls' command:
find -mtime +n -ls
These are simple commands, but very useful.
Modify as per your need.
Thanks!
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......