Re: to make file size o in a shell ?

From: Floyd L. Davidson (
Date: 03/30/04

Date: Mon, 29 Mar 2004 18:46:19 -0900

"David Schwartz" <> wrote:
>"Floyd L. Davidson" <> wrote:
>> "somez72" <> wrote:
>>>I just want to truncate the file(tmp/mylog.dat) with size 0 , in a shell
>> >tmp/mylog.dat
> That won't work. His next write will restore the file to its original

That is precisely the way it is done (typically for syslog files
in /var/log, as an example), assuming the intention is to avoid
having to re-open the log file after it has been

> He has to open the file in append mode. Otherwise, he's going to have to
>code exactly what he wants because the system has no idea what it should do.
> For example, suppose the file is 1,024 bytes long. He seeks to byte 43
>and is about to write 10 bytes when the file is truncated to size zero.
>Where should the forthcoming 10 byte write go?

Yes, his C code has to comply. The point is, the file need not
be closed and reopened, which is exactly what must happen if it
is rm'd.

Floyd L. Davidson           <>
Ukpeagvik (Barrow, Alaska)               

Relevant Pages