Is it safe to remove all files in the /var/log when cleaning a server's history?

Solution 1:

no, not really. Some log files will not be recreated by the processes writing to them. You might better blank the logfiles, like cat /dev/null > /var/log/

Solution 2:

Some daemons won't be happy until you kill -HUP them so they know that their log file has changed (more particularly when it's a mv). You should know what their behavior is before you do this.

You should consider using mv, kill -HUP then shred the moved file (instead of cp or echo).

Also, you might want to read man 8 logrotate for further information.

Solution 3:

reputation too low for commenting, so I put it in an answer:

To blank each file in /var/log/ including subdirectories, you could issue

find /var/log/ -type f -exec cp /dev/null {} \;

(naturally this is untested)

I would assume yes, it is safe to blank them. However no one will be able to tell for sure without examining the list of logfiles in there or the applications that created them. Debian policy suggests that it should be safe but probably no one has tried.

If I were you, I would preserve a copy of the directory and check the system's functions afterwards. And not forget to remove the backup :)