How to zero out a file in tcsh?
John Jannotti
jj at lcs.mit.edu
Fri Feb 7 11:45:56 EST 2003
Jerry Feldman <gaf at h0020780e341c.ne.client2.attbi.com> writes:
> On Thu, 6 Feb 2003 22:29:15 -0500
> Derek Martin <blu at sophic.org> wrote:
>
> > One method to do this regardless of how your shell handles redirection
> > and what flavor of echo you have is this:
> >
> > rm filename; touch filename
> I fully concur with Derek. This is full portable accross all versions of
> Unix and Linux. As mentioned in the other posts, echo, while a shell
> builtin may have different behavior depending on the shell.
But it doesn't do the same thing. The other examples truncate the existing
file, this doesn't. It's possible this makes a difference. One of the
reasons you might be doing this is to reclaim disk space. If a process has
the file open, truncating it still reclaims the space, deleting it doesn't.
Or, perhaps you know that something is doing the equivalent of "tail -f" on
the file, and another process is appending to it. If you delete and
recreate, those processes are not talking to each other any more.
I think "cat > filename", then ^d is probably the shortest portable
way. (or echo -n > filename is you're not interactive).
jj
More information about the Discuss
mailing list