how to overwrite the content of a file

Adam Vande More amvandemore at
Thu Nov 11 20:16:34 UTC 2010

On Thu, Nov 11, 2010 at 2:02 PM, Matthias Apitz <guru at> wrote:

> What is the best method to overwrite the blocks of a given file with
> bytes of 0x00, i.e. not to O_TRUNC away the blocks to the freelist of the
> file system, but overwrite the old blocks?
> I've checked
> $ dd if=/dev/zero of=file count=4
> but dd(1) opens the file with O_RDWR|O_CREAT|O_TRUNC which for sure will
> give away the old blocks and adquire new blocks. Any idea?

Well there is "rm -P" although I'm not sure that accomplished exactly what
you are looking for.

Adam Vande More

More information about the freebsd-questions mailing list