Erase free disk space from the command line
Thu, Apr 24 2008 at 7:30AM PDT • Contributed by: mubarak
Thu, Apr 24 2008 at 7:30AM PDT • Contributed by: mubarak
It is possible to use Disk Utility to erase the free space on a disk. However, I had difficulty finding a command, such as hdiutil, to do it from the command line. One advantage of doing it from the command line is that it is easier to use cron or launchd to automate the process.
It turns out the solution is relatively straightforward:
[robg adds: I haven't tested this one...however, I'd be somewhat cautious about using it on your boot drive. Running out of space on the boot drive -- even briefly -- may cause issues. If you know more about that possibility than I do, please comment!]
It turns out the solution is relatively straightforward:
cat /dev/zero > /private/tmp/junk; rm /private/tmp/junk
The first part of the command will keep enlarging a file with zeros until disk space runs out. After an error, the second part will delete the empty file. Lather, rinse, repeat for extra security (7-pass, 35-pass Guttman).
[robg adds: I haven't tested this one...however, I'd be somewhat cautious about using it on your boot drive. Running out of space on the boot drive -- even briefly -- may cause issues. If you know more about that possibility than I do, please comment!]
•
[14,229 views]
