# Fill with random bytes.
sync # Flush buffers again.
dd if=/dev/zero of=$file bs=$BLOCKSIZE count=$flength
# Fill with zeros.
sync # Flush buffers yet again.
let "pass_count += 1"
rm -f $file # Finally, delete scrambled and shredded file.
sync # Flush buffers a final time.
echo "File \"$file\" blotted out and deleted."; echo
# This is a fairly secure, if inefficient and slow method
#+ of thoroughly "shredding" a file.
# The "shred" command, part of the GNU "fileutils" package,
#+ does the same thing, although more efficiently.
# The file cannot not be "undeleted" or retrieved by normal methods.
# However . . .
#+ this simple method would *not* likely withstand
#+ sophisticated forensic analysis.
# This script may not play well with a journaled file system.
# Exercise (difficult): Fix it so it does.
# Tom Vier's "wipe" file-deletion package does a much more thorough job
#+ of file shredding than this simple script.
# For an in-depth analysis on the topic of file deletion and security,
#+ see Peter Gutmann's paper,
#+ "Secure Deletion of Data From Magnetic and Solid-State Memory".
See also the dd thread entry in the bibliography.
The od, or octal dump filter converts input (or files) to octal (base-8) or other bases. This is useful for
viewing or processing binary data files or otherwise unreadable system device files, such as
/dev/urandom, and as a filter for binary data.
head -c4 /dev/urandom | od -N4 -tu4 | sed -ne '1s/.* //p'
# Sample output: 1324725719, 3918166450, 2989231420, etc.
# From rnd.sh example script, by Stéphane Chazelas
See also Example 9-16 and Example A-36.
Performs a hexadecimal, octal, decimal, or ASCII dump of a binary file. This command is the rough
equivalent of od, above, but not nearly as useful. May be used to view the contents of a binary file, in
combination with dd and less.
dd if=/bin/ls | hexdump -C | less
# The -C option nicely formats the output in tabular form.
Advanced Bash-Scripting Guide
Chapter 16. External Filters, Programs and Commands