<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d11356004\x26blogName\x3dxception\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://openrent.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://openrent.blogspot.com/\x26vt\x3d-2179510228592399674', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Clear a log file without deleting it

Need to clear out a log file to get rid of the "noise" in it? I do that often when tracking down a problem. However, deleting it usually means restarting the service that spawned it, which is not always possible (on a production server). The solution is to use redirection and the so-called "bit bucket" to get this done.

You clear the contents of a file (by sending it null data), but keep the file itself. Here's how:

Lets say we are not happy that the "lastlog" file has grown to 19 megabytes in size.

# ls -ltr lastlog
-r-------- 1 root root 19M Feb 6 12:34 lastlog

So we fill up the lastlog file with nothingness from /dev/null:
# cat /dev/null > lastlog

Ahhh, now lastlog is a good size!
# ls -ltr lastlog
-r-------- 1 root root 0 Feb 6 12:34 lastlog