How to zero out a file in tcsh?
dgavin at davegavin.com
dgavin at davegavin.com
Fri Feb 7 11:58:23 EST 2003
the "rm filename; touch filename" variation doesn't necessarily preserve
ownership or permissions depending on who does it and what their umask is.
My personal favorite is "cat /dev/null > filename".
Dave Gavin
Quoting John Jannotti <jj at lcs.mit.edu>:
>
>
>
> 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
>
> _______________________________________________
> Discuss mailing list
> Discuss at blu.org
> http://www.blu.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list