File remove command?

Bob McGowen x4312 dept208 bob at wyse.wyse.com
Fri Jun 21 10:32:08 AEST 1991


In article <1991Jun17.181558.9562 at newshost.anu.edu.au> cmf851 at anu.oz.au (Albert Langer) writes:
>In article <922 at visenix.UUCP> beattie at visenix.UUCP (Brian Beattie) writes:
>
>>If the real aim is to remove the data how about:
>>
>>cat /dev/null >offendingfile
>>rm offendingfile
>>
>>This may leave the inode if links exist but the file will
>>have been truncated to zero length i.e. no data.
>
>Does this also get rid of the data from the original file system
>blocks so they cannot be reconstructed with a file system debugger?

---deleted lines---

>How does one fill a file with zeroes or whatever in as few keystrokes
>as possible? ed?
>

I do not know about the "in as few keystrokes as possible", but the
following script will overwrite the file space.  If you have SysV
echo with octal escapes, you can overwrite with all nulls, if not
the first character or two will be standard ascii followed by nulls.
This procdure will only produce null padding (no choice) since it
uses the dd option for pading input records to the input block size
specified to dd (this will be clearer after you read the script, I
think).  THERE IS A MAJOR PROBLEM:  The amount of system RAM available
to the user will affect how big a file can be handled by this procedure.
I have tested the basics from the command line on UNIX System V/386
on a text file of 1291 bytes.  du output was 3 blocks.  The result
of the dd line made a file of 1536 (3*512) bytes, all nulls.
I hope this is of interest to someone out there.  ;-)

The script also uses  cut -f1  to get the first field from the output
of du.  If you do not have cut, use  awk '{print $1}'  instead.

------cut------------cut------------cut------
#!/bin/sh
#
# No error checking on file, for brevity.  You should add it.

file=$1

# determine number of blocks in the file
blks=`du -a $file`

# using SysV echo to generate a null for input to dd, use dd
# conv=sync option to pad the input with nulls to the specified
# block size, which just happens to be the file size.  NOTE:  the
# size of the file will determine if this will work, since you
# must have enough memory to hold the blocksize data that will be
# written over the file.  The usuall dd output is sent to /dev/null.

/bin/echo '\0\c' | dd of=$file ibs=${blks}b conv=sync 2>/dev/null

rm -f $file

exit


Bob McGowan  (standard disclaimer, these are my own ...)
Product Support, Wyse Technology, San Jose, CA
..!uunet!wyse!bob
bob at wyse.com



More information about the Comp.unix.shell mailing list