Categories
Tutorial

Keep first N lines of a log file with Cron

If you wish to keep first (top) N lines of a log file and delete the older lines, you can use this command with Cron:

echo "$(head -100 /home/user/public_html/log.txt)" > /home/user/public_html/log.txt

Categories
Tutorial

Keep last N lines of a log file with Cron

If you wish to keep last (bottom) N lines of a log file and delete the older lines, you can use this command with Cron:

echo "$(tail -100 /home/home/public_html/log.txt)" > /home/home/public_html/log.txt