Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 07-12-2010, 05:29 PM   #1
Registered: Apr 2004
Posts: 340

Rep: Reputation: 30
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.
Old 07-12-2010, 05:49 PM   #2
Senior Member
Registered: Aug 2009
Posts: 3,790

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

Old 07-12-2010, 10:22 PM   #3
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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":

filesize=$(stat -c %s mystuff)
dd if=/dev/zero of=mystuff bs=1 count=$filesize
Old 07-13-2010, 08:43 AM   #4
LQ Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287
'shred' will work as well.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
split a gzip file based on size and have a prefix without changing extension gubbu Linux - Newbie 3 01-18-2010 05:09 PM
Create a Multiple files by reading a input file and changing the contents bhargavkr Linux - Newbie 4 09-17-2009 12:37 AM
using sed to insert line into file and overwrite the current file jadeddog Programming 3 06-11-2009 07:14 PM
Changing file system size yusufs Linux - Newbie 1 10-16-2008 10:17 AM
Bash remove part of a file based on contents of another file bhepdogg Programming 4 01-31-2007 03:13 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration