Securely delete files on the Mac without sending them to Trash

How do you delete a file in macOS on the Apple Mac? You might think it is a simple question, but there is more to it than that and files deleted that way can be recovered. Bypass the Trash!
Of course, everyone knows that to delete a file you just drag it to the Trash, but that is not deleting it, it simply moves it to another folder on the disk. You can empty the Trash, but that deletes all of the files in it, which still leaves the question, how do you delete one file?
You must open the Trash, find the file you deleted and then Ctrl+click it and select Delete Immediately. Not so long ago you could not do this and you had to empty the whole Trash just to get rid of one file!
The reason for the Trash folder is so that files can be recovered if you discover that you really needed one that was deleted. Emptying the whole Trash just to get rid of one file was crazy. Glad that is fixed these days, however, it could still be simpler than deleting, opening the Trash, finding the file and deleting it again.
What's more, suppose you have a whole group of files, such as raw video footage that you no longer need. You decide to delete them to free up disk space, so you drag them to the Trash. Unfortunately, this does not free up disk space because the files are simply moved to the Trash folder on the disk. Emptying the Trash means that lots of other files that you might discover you actually need, are removed too.
There are solutions and one method is to select one or more files or folders, click the File menu, hold down the Option key and select Delete Immediately. This bypasses the Trash.
This is good, but it does not securely delete a file and it might be recoverable, especially if it is on an external hard disk drive or thumb drive. People often don't encrypt external drives.
Delete files from the Terminal
Files can be deleted from a Terminal command prompt and they can be overwritten to destroy any data they contain before being deleted. To see how this works, go to the Applications/Utilities folder and run Terminal. This opens a command prompt window on the desktop. We will be using the rm command and typing man rm shows the manual if you want to read up about it.
To delete a file, enter:
rm –f filename
Where filename is the name and path of the file or folder that you want to delete. The rm command stands for remove. A slight modification of this command is:
rm –rf filename
The –rf are command line switches and r means work recursively, so if filename is a folder, which contains another folder, it will dig down through them deleting all the files in the folder and subfolders. The f means ignore non-existent files and never prompt, or in other words, just get on with it and don’t bother me.
One final variation of this is:
rm –rfP filename
The extra command line switch P, tells the rm command to overwrite the file three times before deleting it, to ensure it cannot be recovered by anyone.
Take care at the Terminal
The potential for typing errors when entering filenames and paths is great and you could enter the wrongfile or folder, so after typing rm –rfP (and a space), drag the file or folder from a Finder window and drop it on the command line in the Terminal window to automatically insert the path. It saves typing it and you will not get any errors this way.
However, there is an even better way and we can use an Automator app.
Create an Automator app
No-one wants to be bothered with typing complicated Terminal commands every time they want to delete a file, so here is a much better method. Write an Automator script. Automator is a sort of very simple programming language that is bundled with macOS and it can be used to create all sorts of apps. For example, it can be used to create an app to delete files and folders without sending them to the Trash.
Start Automator from the Applications folder and create a new application. Notice that the description at the bottom says “Any files or folders dropped onto an Application will be used as input to the workflow.” This means that we can drag and drop files and folders onto our Automator app.

After selecting the document type, go to the Library on the left and select the Utilities category and then Run Shell Script.

Drag Run Shell Script and drop it in the empty area on the right. An item like the one above appears and it contains a default script. We need to modify it, but first, notice that at the top it says “Application receives files and folders as input”. Select as arguments in the Pass input item on the right. The files we want to delete will be passed to the script.

Then we need to to replace the default echo command that Run Shell Script adds with the rm -rfP command used earlier to delete files and folders. The "$f" at the end, which we keep, means the files or folders passed to it, which will be come clear later.
Safety precautions
As it stands, there are no second chances and no opportunity to change your mind. As soon as you pass a file or folder on the app, it is gone forever with no questions asked.
If you prefer to have a safety net, select Utilities in the Library on the left, then Ask for Confirmation in the next list. Drag Ask for Confirmation to the area on the right and drop it just above the RunShell Script item. It will look like this:

Edit the title and enter a message to display on the screen. The button text can also be edited if it is clicked.
Save the Automator app
The app is finished and we just need to save it. Click Save on the File menu and save it as an application in the Applications folder. Here is it called appropriately, Secure Erase.app.

How to use Secure Erase
You could open the Applications folder and then drag files and folders to it and drop them from another Finder window, but a better solution is to drag the app from the Applications folder and drop it on the Dock among all the other app icons. The Automator icon is displayed in the Dock and when the mouse is over it, it shows the app name.
Now you can drag one or more files and folders from Finder windows and drop them on Secure Erase in the Dock to delete them without moving them to the Trash folder.

The app asks if you are sure and clicking Cancel will quit without deleting the files. You must click OK to confrm it. You now have a Dock icon that securely deletes files and bypasses the Trash folder. Only delete files this way that you never want again, otherwise drag files to the Trash which stores them until you empty it.
You have also taken your first step to becoming a programmer by creating an app!
Use a utility
Not everyone has the time or inclination to create their own app to securely delete files, so there are utilities that can do it for you, like this one. It is a multi-function app that does many things and the Shredder securely erases files.

I have been using CleanMyMac X for a while now and it seems pretty good. (Affiliate links ahead!) If you want to know more, see CleanMyMac X features here, to check the latest price for CleanMyMac X.



