Ubuntu

Ubuntu – clear all log files

If you want to clear all your log files, not just those in the first-level log folder, you could use:

shopt -s globstar                  # if needed
truncate -s 0 /var/log/*.log       # first-level logs
truncate -s 0 /var/log/**/*.log    # nested folders, like /var/log/nginx/access.log

Noting that if you already have logrotate running, you’ll need to clear out the rotated .gz logs as well:

find /var/log -type f -name '*.[0-99].gz' -exec rm {} +

A valid use for this could be building a VM appliance container for distribution, for example.

You should not need to do this as part of routine maintenance: as D-E-M quite correctly suggested, use logrotate for that.

Similar Posts