-4

I want to clear the server logs in Linux without having to restart server, so that I dont get Out of Memory issue. I heard that > filename would do that but that contents are stored to some other memory. SO i don't think that command would reduce the memory? Is there any way to clear log file.

2
  • what makes you think log files are taking up significant physical memory? that is not usually the case, unless you have attempted to open the log. Most of the time you just append to the log file, which doesn't require the whole file to be loaded into RAM. Or do you mean disk space? Dec 15, 2014 at 5:58
  • "Out of Memory" sounds like RAM, but without more info it's impossible to tell. You're not keeping your log files in RAM are you? On a tmpfs? Lot files usually just sit on a physical drive
    – Xen2050
    Dec 15, 2014 at 6:42

1 Answer 1

1

About clearing out or reducing system logs, that sounds like "Log Rotation" (often handled with logrotate). See this Ubuntu-oriented help page for more info: https://help.ubuntu.com/community/LinuxLogFiles#Log_Rotation

When viewing directory listings in /var/log or any of its subdirectories, you may encounter log files with names such as daemon.log.0, daemon.log.1.gz, and so on. What are these log files? They are 'rotated' log files. That is, they have automatically been renamed after a predefined time-frame, and a new original log started. After even more time the log files are compressed with the gzip utility as in the case of the example daemon.log.1.gz. The purpose of log rotation is to archive and compress old logs so that they consume less disk space, but are still available for inspection as needed. What handles this functionality? Why, the logrotate command of course! Typically, logrotate is called from the system-wide cron script /etc/cron.daily/logrotate, and further defined by the configuration file /etc/logrotate.conf. Individual configuration files can be added into /etc/logrotate.d (where the apache2 and mysql configurations are stored for example).

This guide will not cover the myriad of ways logrotate may be configured to handle the automatic rotation of any log file on your Ubuntu system. For more detail, check the Resources section of this guide.

NOTE: You may also rotate system log files via the cron.daily script /etc/cron.daily/sysklogd instead of using logrotate. Actually, the utility savelog may produce unexpected results on log rotation which configuring logrotate seems to have no effect on. In those cases, you should check the cron.daily sysklogd script in /etc/cron.daily/sysklogd and read the savelog manual page to see if savelog is not in fact doing the rotation in a way that is not what you are specifying with logrotate.

Or, you could just delete them... rm etc...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .