shred targetfile

Securely destroy data (including whole hard disks)

GNU shred is provided by the coreutils package on most Linux distribution (meaning, you probably have it installed already), and is capable of wiping a device to DoD standards. You can give shred any file to destroy, be it your shell history or a block device file (/dev/hdX, for IDE hard drive X, for example). Shred will overwrite the target 25 times by default, but 3 is enough to prevent most recovery, and 7 passes is enough for the US Department of Defense. Use the -n flag to specify the number of passes, and man shred for even more secure erasing fun. Note that shredding your shell history may not be terribly effective on devices with journaling filesystems, RAID copies or snapshot copies, but if you're wiping a single disk, none of that is a concern. Also, it takes quite a while :)

5
By: sud0er
2009-04-28 19:57:43

These Might Interest You

  • Intentional hash in the beginning. May run a looong time. Wipes your data for real. Was meant to be /dev/urandom - I mistyped it. :-)


    2
    # for i in $(seq 1 25); do dd if=/dev/urandom of=<your disk> bs=1M ; done
    danam · 2009-09-29 07:12:34 3
  • This command generates a pseudo-random data stream using aes-256-ctr with a seed set by /dev/urandom. Redirect to a block device for secure data scrambling.


    4
    openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero > randomfile.bin
    malathion · 2014-06-02 18:12:54 1
  • This command will use the fdisk utility to find all block devices on your system, and overwrite them with data from the /dev/urandom non-blocking random number generator. CAUTION: This will irrevocably erase EVERY SINGLE physical block storage device visible to the fdisk utility, including plugged USB devices, RAID sets, LVM, etc. Show Sample Output


    1
    for i in `sudo /sbin/fdisk -l |grep Disk |grep dev |awk '{ print $2 }' |sed s/://g` ; do sudo /usr/bin/dd if=/dev/urandom of=$i bs=8M & done
    aimana007 · 2014-03-16 12:04:59 0
  • This is a bit to bit copy so if you have a 500GB hard disk it will take a long time even if have Gigabit Ethernet


    -1
    Boot up destination machine with Knoppix live CD and run nc -l -p 9000 | dd of=/dev/sda Then on the master dd if=/dev/sda | nc <dest-ip> 9000 You can monitor bandwidth usage to see progress: nload eth0 -u M
    lv4tech · 2009-05-07 05:26:58 3

  • -7
    df -H
    Calida · 2009-03-02 13:32:23 1
  • This is to pull all the saved S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology) information from a hard drive. This can give you an idea of the nature and extent of an issue on a failing hard drive. Show Sample Output


    1
    smartctl --attributes /dev/sda
    ShadowCat8 · 2011-10-13 20:21:03 0

What Others Think

I still use dd a number of times. But if you want to destroy stuff, why not take the medium to your local drill press and let metal shavings fly?
kaedenn · 472 weeks and 5 days ago
Shred works well. You can't run it from the partition being wiped. It is slow, though.
fritz_monroe · 472 weeks and 4 days ago
Thanks for pointing that out, fritz. Yeah, I was worried about people thinking this was equivalent to one of the "sudo rm -rf /" malicious posts, when its really about erasing data securely. Shred is smart enough not to roast /dev/hda when you're running off of it. Kaedenn, in my tests, shred is slightly faster (and easier) than a comparable set of dd's. I didn't test the drill press, but I'd expect that would be quite a bit faster. Harder to re-purpose your old drives afterward, tho.
sud0er · 472 weeks and 4 days ago
For regular files, BSD includes the -P option with the "rm" utility: -P Overwrite regular files before deleting them. Files are over- written three times, first with the byte pattern 0xff, then 0x00, and then 0xff again, before they are deleted. Files with multi- ple links will be unlinked but not overwritten.
Resolution · 472 weeks and 4 days ago
why not just use dd. dd if=/dev/zero of=/dev/ doing this multiple times isn't needed. read up, and stop wasting time overwriting multiple times or destroying perfectly good drives. http://16systems.com/zero.php if skilled scientists with electron microscopes can't recover any usable data from a single pass dd wipe, who do you think can?
urpwnd · 472 weeks 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: