How to: Erase Hard Drives at Linux Command Line

How to: Erase Hard Drives at Linux Command Line

The simplest way is the dd command. Simply type:
dd if=/dev/zero of=/dev/

This process takes a while but it will write zeros to the whole hard drive. The DD command can also be used to write zeros to just one partition, and should work on just about any Unix or Unix like system. But this may not be the end all and you’ll want a bit more security. Luckily several utilities exist for just such an occasion.

Wipe is one of the better ones I’ve seen. It claims to use the Gutmann method as one of it’s processes.

Another method is one of the simplest and makes reading man pages profitable. The good old rm command with -P does a three time wipe on each file, by (according to the man page) writing “first with the byte pattern 0xff, then 0x00, and then 0xff again.

Secure rm or “srm” is a fancy remove program that overwrites the files it deletes much like rm -P command. By default it overwrites, renames, then truncates the file(s) before unlinking and removing them. Two flags can be specified for the really paranoid, -m does “overwrite the file with 7 US DoD compliant passes (0xF6, 0x00, 0xFF, random, 0x00, 0xFF, random)” and -z which zeros the files after overwriting. So srm -rf -m -z /dev/<drive name>/ would do a pretty good job of killing everything on the hard drive.

Another trick I picked up from the FreeBSD mailing list is: split -b 200m /dev/random randomdata ; sync && rm randomdata* This uses part of my preferred method of splitting the hard drive into multiple partitions then writing random data over each piece. If can be ran as many times as needed and by changing the -b flag’s size could make most data very unreadable.

And last but not least, Techrepublic has a post about using Shred to delete files and filesystems.

How To: Check OS X Disk Usage

How To: Check OS X Disk Usage

In OS X there are two ways to do everything. Via the GUI, or Via the command line. Frequently the GUI method does fine for most uses. But sometimes a bit more information is needed.

In the GUI, getting Disc Usage is simple. Open Finder, click on the drive and look at the bottom of the finder window. The number of files selected and the space available is displayed. But, this only shows the current directory and includes ALL sub folders under it.

But with a little use of the command line we can get a lot more information. Opening terminal defaults to the active user’s home directory.

At this point type du -sh * We’re adding the s for “Display an entry for each specified file,” and h for “Human-readable” output.

This will give a readout like this:
28G Desktop
41G Documents
13G Downloads
3.9G Library
0B Movies
5.1G Music
42G Pictures
121M Public
374M Sites

As can be seen this then gives a readout of each directory in the current one and provides the total space it takes up. In cases of low hard drive space this gives a good way to quickly find folders that may be too big. It could also be run in the /Users folder on multi-user machines to find out who it using all the hard drive space.