Delete files in OS X without sending them to the Trash

Robot

How do you delete a file in OS X on the Apple Mac? You might think that it is silly to ask such a simple question, of course, everyone knows that to delete a file you just drag it to the Trash. That is not deleting it, it simply moves it to another folder on the disk. You empty the Trash of course, but that deletes all of the files in the Trash, which still leaves the question, how do you delete one file?

It is really odd that Apple has never addressed this problem and 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 is crazy.

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.

An even worse problem is that if you delete files on external storage, such as a USB disk drive or USB flash memory drive (thumb drive), the disk space is not recovered. This means that more and more space is used on the thumb drive until it is full, even though it looks empty. You have to empty the Trash, which deletes files on the Mac’s internal disk drive, in order to recover the disk space on the external device. It is madness!

There are two solutions and the first one you won’t like, but the second one is really useful.

Delete files from the Terminal

Go to the Applications/Utilities folder and run Terminal. This opens a command prompt window on the desktop. To delete a file, enter:

rm –rf filename

Where filename is the name and path of the file or folder that you want to delete. The rm command stands for remove. 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.

The potential for typing errors when entering filenames is great and you could enter the wrongfile or folder, so after typing rm –rf, drag the file or folder from a Finder window and drop it on the command line to automatically insert it. It saves typing it and you will not get any errors.

Write an Automator script

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 OS X and it can be used to write 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.

Create an Automator application

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

Write an Automator workflow

Drag Run Shell Script and drop it in the empty area on the right. An item like this appears. 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. A little program is automatically written for you.

Edit the Automator script

This basically means, for every file/folder passed to the app, echo (print on the screen) the filename until done. What we want to do is to replace this command with the rm –rf command used earlier to delete files and folders.

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, Skip The Trash.app.

Create an Automator app

You could place the app on the desktop and drag files and folders to it from Finder windows, but a better solution is to drag the app from the Applications folder and drop it on the Dock. The Automator icon is displayed and when the mouse is over it, it shows the app name, Skip The Trash. Just drag files and folders from Finder windows and drop them on Skip The Trash to delete them without moving them to the Trash folder.

Add an app to the Dock

Safety precautions

As it stands, there are no second chances and no opportunity to change your mind. As soon as you drop a file or folder on Skip The Trash it’s gone forever with no questions asked.

If you prefer to have a safety net, return to Automator and open the app. 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:

Automator scripts

Edit the title, enter a message, and edit the button text so it looks like the image above. Save the app again and now when you drop files on Skip The Trash, a message pops up like this:

It asks if you are sure and clicking No will quit without deleting the files. You now have a Dock icon that really deletes files in addition to the Trash which stores files until you empty it. You have also taken your first step to becoming a programmer by creating an app.

OS X El Capitan update

Is this new in OS X El Capitan? You can now select a file or folder on the desktop or in a Finder window, go to the File menu, hold down Option and the Move to Trash menu option becomes Delete Immediately. The file or folder is deleted without being moved to the Trash.

 

Tags: 
Share

Add new comment

By submitting this form, you accept the Mollom privacy policy.

Related items you will like...