Delete all of /var/log?

Can I delete everything in /var/log? Or should I only delete files (recursively) in /var/log but leave folders?

Does anyone have a good rm command line? (My admin skills leave me nervous.)

Note: I am using Debian. I am not sure what version.


Solution 1:

Instead of deleting the files you should rotate them, e. g. using logrotate.

You never know when you'll actually need the logs from some time ago, so it's better to archive them (up to a reasonable age, e. g. 3 months).

logrotate can compress your old log files so they don't occupy a lot of disk space.

Solution 2:

Delete all files:

find /var/log -type f -delete

Delete all .gz and rotated file

find /var/log -type f -regex ".*\.gz$"
find /var/log -type f -regex ".*\.[0-9]$"

Try run command without "-delete", to test it.