securely overwrite a file with random junk, rename it to clear the directory entry and finally delete it

shred -vzu /tmp/junk-file-to-be-shredded
Sample Output
$ shred -vzu /tmp/junk-file-to-be-shredded
shred: /tmp/junk-file-to-be-shredded: pass 1/26 (random)...
shred: /tmp/junk-file-to-be-shredded: pass 2/26 (dddddd)...
shred: /tmp/junk-file-to-be-shredded: pass 3/26 (bbbbbb)...
shred: /tmp/junk-file-to-be-shredded: pass 4/26 (333333)...
shred: /tmp/junk-file-to-be-shredded: pass 5/26 (249249)...
shred: /tmp/junk-file-to-be-shredded: pass 6/26 (eeeeee)...
shred: /tmp/junk-file-to-be-shredded: pass 7/26 (cccccc)...
shred: /tmp/junk-file-to-be-shredded: pass 8/26 (888888)...
shred: /tmp/junk-file-to-be-shredded: pass 9/26 (ffffff)...
shred: /tmp/junk-file-to-be-shredded: pass 10/26 (666666)...
shred: /tmp/junk-file-to-be-shredded: pass 11/26 (555555)...
shred: /tmp/junk-file-to-be-shredded: pass 12/26 (777777)...
shred: /tmp/junk-file-to-be-shredded: pass 13/26 (random)...
shred: /tmp/junk-file-to-be-shredded: pass 14/26 (444444)...
shred: /tmp/junk-file-to-be-shredded: pass 15/26 (db6db6)...
shred: /tmp/junk-file-to-be-shredded: pass 16/26 (b6db6d)...
shred: /tmp/junk-file-to-be-shredded: pass 17/26 (000000)...
shred: /tmp/junk-file-to-be-shredded: pass 18/26 (999999)...
shred: /tmp/junk-file-to-be-shredded: pass 19/26 (492492)...
shred: /tmp/junk-file-to-be-shredded: pass 20/26 (aaaaaa)...
shred: /tmp/junk-file-to-be-shredded: pass 21/26 (924924)...
shred: /tmp/junk-file-to-be-shredded: pass 22/26 (6db6db)...
shred: /tmp/junk-file-to-be-shredded: pass 23/26 (222222)...
shred: /tmp/junk-file-to-be-shredded: pass 24/26 (111111)...
shred: /tmp/junk-file-to-be-shredded: pass 25/26 (random)...
shred: /tmp/junk-file-to-be-shredded: pass 26/26 (000000)...
shred: /tmp/junk-file-to-be-shredded: removing
shred: /tmp/junk-file-to-be-shredded: renamed to /tmp/000000000000000000000000
shred: /tmp/000000000000000000000000: renamed to /tmp/00000000000000000000000
shred: /tmp/00000000000000000000000: renamed to /tmp/0000000000000000000000
shred: /tmp/0000000000000000000000: renamed to /tmp/000000000000000000000
shred: /tmp/000000000000000000000: renamed to /tmp/00000000000000000000
shred: /tmp/00000000000000000000: renamed to /tmp/0000000000000000000
shred: /tmp/0000000000000000000: renamed to /tmp/000000000000000000
shred: /tmp/000000000000000000: renamed to /tmp/00000000000000000
shred: /tmp/00000000000000000: renamed to /tmp/0000000000000000
shred: /tmp/0000000000000000: renamed to /tmp/000000000000000
shred: /tmp/000000000000000: renamed to /tmp/00000000000000
shred: /tmp/00000000000000: renamed to /tmp/0000000000000
shred: /tmp/0000000000000: renamed to /tmp/000000000000
shred: /tmp/000000000000: renamed to /tmp/00000000000
shred: /tmp/00000000000: renamed to /tmp/0000000000
shred: /tmp/0000000000: renamed to /tmp/000000000
shred: /tmp/000000000: renamed to /tmp/00000000
shred: /tmp/00000000: renamed to /tmp/0000000
shred: /tmp/0000000: renamed to /tmp/000000
shred: /tmp/000000: renamed to /tmp/00000
shred: /tmp/00000: renamed to /tmp/0000
shred: /tmp/0000: renamed to /tmp/000
shred: /tmp/000: renamed to /tmp/00
shred: /tmp/00: renamed to /tmp/0
shred: /tmp/junk-file-to-be-shredded: removed

0
By: mpb
2009-06-18 12:00:19

What Others Think

It's worth pointing out that this isn't reliable on most modern (journalling) filesystems, including many installed by default (particularly on Linux: ext3, ext4).
MikeCamel · 531 weeks and 2 days ago
-n33 #when you overwrite more than the number of bits of your CPU you ensure that it is reliable for 64-bit folks use -n65 ... have fun waiting ... or use screen ...
copremesis · 531 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: