Terminal 101: Securely Erasing Files with SRM
Posted 02/04/2013 at 12:04pm
| by Cory Bohon
Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!
When erasing files on your Mac (or any computer for that matter), trashing a file only removes the pointers to the file(s) on the hard drive. The file is still there, and intact. If you want to completely erase the file, then a secure erase is your only option: After removing the file pointers, the secure erase will randomly write data over top of the erased file to reduce the possibility of the file being read in the future. Continue reading and we’ll show you how to use the srm command to securely remove files from your Mac in the Terminal.
Erasing Files with RM

As we’ve shown you in the past, you can easily remove files from your Mac using the following command:
rm -r pathToFileOrFolder
Replace pathToFileOrFolder with the path and name of the file or folder that you wish to remove. The -r tells the command that you wish to remove the contents of directories (or a recursive delete).
Erasing Files with SRM

Securely erasing files from your Mac can be just as easy as using the rm command; simply place an “s” in front of the “rm” like this:
srm -r pathToFileOrFolder
Replace pathToFileOrFolder with the path and name of the file or folder that you wish to remove. All of the flags (-r, etc.) that the rm command can utilize also works on the srm command.
Unlike the standard rm, srm overwrites the data in the target files before removing the pointers to the files. This prevents command-line recovery of the data, and may also help bar physical examination of the disk, although it's unlikely that it can completely prevent that type of recovery. It is, essentially, a paper shredder for sensitive files.
Use the srm command to securely remove sensitive data from your machine.
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author on Twitter.