Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

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
8
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.

Alternatives

There are 26 alternatives - 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 271 weeks ago

@bwoodacre

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 271 weeks 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 271 weeks ago

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

Comment by linuxrawkstar 271 weeks 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 270 weeks and 6 days ago

@pixelbeat

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 270 weeks and 6 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts