Wednesday, April 9, 2008

Truncate a file

While setting up Apache HTTP Server to rotate logs I came across an interesting problem. How would you truncate a file? The trivial solution that I came up with was


[root@lambda ~]# rm -f /var/log/httpd/foo.log
[root@lambda ~]# touch /var/log/httpd/foo.log


Unfortunately this doesn't work. The HTTP Server ceases logging to the file unless there is a server restart. After prying around the web I came across some interesting tricks but the one that stood out was:


[root@lambda ~]# :> /var/log/httpd/foo.log
Categories: ,

0 comments: