Delete Archived and Rotated Log Files on Linux

Delete Archived and Rotated Log Files on Linux

Linux systems generate various log files to track system activity, errors, and application events. Over time, these log files can accumulate, taking up disk space, especially archived or rotated logs. Cleaning up old or compressed log files can help free up space and maintain system performance. This tutorial explains how to delete archived and rotated log files on Linux.

Most archived log files are compressed with gzip and have the .gz extension. To delete these files, we can run:

sudo find /var/log -type f -regex '.*\.gz$' -delete

Some log files are rotated with numeric suffixes (like syslog.1, auth.log.2, etc.). To remove these older log files, run:

sudo find /var/log -type f -regex '.*\.[0-9]$' -delete

These commands permanently delete files. Make sure you don't need them for audits or troubleshooting. You can test the command without deleting by removing -delete option.

Leave a Comment

Cancel reply

Your email address will not be published.