LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How do you overwrite the contents of a file without changing the file size? (https://www.linuxquestions.org/questions/linux-software-2/how-do-you-overwrite-the-contents-of-a-file-without-changing-the-file-size-819472/)

lothario 07-12-2010 05:29 PM

How do you overwrite the contents of a file without changing the file size?
 
We have some large files with sampling data in it.
Don't want to delete these files.
But want to quickly overwrite the file with 0s and/or 1s and preserve the original file size.

kbp 07-12-2010 05:49 PM

Looks like the ideal job for a secure deletion prog... you can use wipe with these args: 'wipe -ZFke <filename>'

cheers

pixellany 07-12-2010 10:22 PM

text data or binary?

For a text file: Use SED to replace every character with something.

Text or binary: If you know the size of the file, then use dd to write all zeros to it.
example: Write all zeros to the file "mystuff":

Code:

filesize=$(stat -c %s mystuff)
dd if=/dev/zero of=mystuff bs=1 count=$filesize


H_TeXMeX_H 07-13-2010 08:43 AM

'shred' will work as well.


All times are GMT -5. The time now is 04:43 PM.