|
Posted by David T. Ashley on 11/29/06 20:23
<veg_all@yahoo.com> wrote in message
news:1164773514.284287.98440@16g2000cwy.googlegroups.com...
>I am looking for a simple way to keep my log files from growing too
> large. Basically I would want something that truncates the off first 25
> kb of a 100kb log file. I could do something with reading in the file
> twice, first to determine number of lines. Then a second time to write
> a copy of the reduced log file. Any simpler workarounds?
You can also do it using the standard Unix "head", "tail", and optionally
"wc" commands. (You can use "man" to look those up.)
For example, if you want to keep the last 20,000 lines of the log:
tail -n 20000 infile >outfile
If you're a clever shell programmer, you may find a way to shift the files
around cleverly so that no appends are lost, but I'm not that clever. You
need to understand Unix file semantics and all that.
Rotating the logs (without actually trying to modify or shorten the current
log file) is actually much simpler (a simple "mv"). Unix file semantics
guarantee that if a file is open and you rename it, any appends to it will
get done. The next open-for-append call will create a new file.
Navigation:
[Reply to this message]
|