What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



securely erase unused blocks in a partition

Terminal - securely erase unused blocks in a partition
# cd $partition; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu ShredUnusedBlocks
2009-06-21 14:17:22
User: mpb
Functions: cd dd shred
securely erase unused blocks in a partition

This command securely erases all the unused blocks on a partition.

The unused blocks are the "free space" on the partition.

Some of these blocks will contain data from previously deleted files.

You might want to use this if you are given access to an old computer and you do not know its provenance.

The command could be used while booted from a LiveCD to clear freespace space on old HD.

On modern Linux LiveCDs, the "ntfs-3g" system provides ReadWrite access to NTFS partitions thus enabling this method to also be used on Wind'ohs drives.

NB depending on the size of the partition, this command could take a while to complete.


There is 1 alternative - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

It looks like you forgot to specify the 'dd' part before if=/dev/zero. Also, be careful when running this on the partition where /home or /tmp is mounted because it can cause weird hangups when applications can no longer create temporary files, like when starting an X session.

Comment by bwoodacre 361 weeks and 5 days ago


Thanks for pointing out the missing "dd". Fixed now.

You are also right about needing to be careful about filling /tmp. Hence the mention of LiveCD.

Comment by mpb 361 weeks and 5 days ago

Doesn't handle slack in the last block of a file. Also other space is probably not overwritten on journalling filesystems.

Comment by pixelbeat 361 weeks and 5 days ago

fwiw dban linux is supposed to be the ultimate shredder...

Comment by linuxrawkstar 361 weeks and 5 days ago

Good point pixelbeat. In more words: in some filesystems, a 10 byte file still takes up (say, for instance) 4069 bytes (4K) of physical disk space. If you want to leave the existing files on the filesystem untouched, then this slack space is unwritable at the filesystem level. Something like ext2 would behave this way, but reiser3 packs many small files into the same block. So expanding a giant file and shredding it is a great start if you want/need to do things in place, but you aren't guaranteed to shred 100% of the unused disk bytes unless you use something at the block-device level like dban.

Comment by bwoodacre 361 weeks and 4 days ago


Where is the slack?

The "dd" creates a single file from all the unused blocks in the partition in a file called "ShredUnusedBlocks".

So the end of this file is the end of the last unused block.

You can use the "df" command after the "dd" to verify 100% of the space in the partition is used up when the "ShredUnusedBlocks" file is created.

Regarding the journal, what do you think the journal will be full of? I think it will be mostly full of writes of random data from the shred command. If the default number of overwrites from shred is not considered enough, it can be increased with the "-n" (or "--iterations=n") option.

Example: specifying "-n16" for 16 iterations:

cd /boot; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu -n16 ShredUnusedBlocks

Comment by mpb 361 weeks and 4 days ago

Your point of view

You must be signed in to comment.