I have two questions about using crontab file:
1.I am using a service. When it runs, a new log file created everyday in a log directory. i want to delete all files that already exist greater 5 day in that log directory
2.I want to delete all the infomation that exist greater than 5 days in a log file( /var/log/syslog)
I don't know how to do that with crontab in linux. Please help me! Thanks in advance!
If you are using logrotate for log rotation then it has options to remove old files, if not you could run something as simple as this once a day in your cron:


find /path/to/log/folder -mtime +5 -type f -exec rm {} \;

Or more specific match a pattern in the filename

find . -mtime +5 -type f -name *.log  -exec ls -l {} \;


Why not set up logrotate for syslog to rotate daily then use its options to remove anything older than 5 days.
Other options involve parsing log file and keeping certain aspect etc removing other bits etc which involved writing to another file and back etc and when it comes to live log files this can end up causing other issues such as a requirement to restart service to relog back into files. so best option would be logrotate for the syslog
How to delete some file with crontab in linux