Re: How to clear the contents of a file?

From: Keith Brown <brownk_at_chem4823.usask.ca>
Date: Mon, 19 Dec 2005 09:53:04 -0600 (CST)

> For Linux gurus out there: How do I clear the contents of a file without
> erasing it? Is there a Linux command that will do this for me in one
> step? I don't want to erase the file, just zero its contents, without
> changing ownership and permissions.
>
> Thanks in advance,

   How about this:

   dd if=filename of=filename ibs=1

This reads one byte from the file and then outputs it to the same file ...
you end up with an empty file. If you end up putting it into a script you
might want to redirect the output to /dev/null or something.

Keith Brown
University of Saskatchewan
Saskatoon, Saskatchewan

-----------------------------------------------------------------------
The gates in my computer are AND, OR and NOT; they are not Bill.
-----------------------------------------------------------------------
Received on Mon Dec 19 2005 - 09:55:54 MST

This archive was generated by hypermail 2.4.0 : Sun Jun 11 2023 - 13:34:36 MST