Selective Delete from the Trash

Posted on January 29th, 2008 in Basic OS Functionality Tagged with: , ,
by admin

Here is a feature in Windows that is missing from the Mac: the ability to selectively delete files from the Trash. If you open the Trash Can, on the far right side of the line with the word Trash, there is a button for Empty. Also under the Finder menu there are commands for Empty Trash… and Securely Empty Trash… This is much the same as in Windows.

However, in Windows if you are looking at the Recycle Bin in Windows Explorer and select one or more files and then either hit the Delete key or select Delete from the context sensitive menu (from mouse button 2) then just those files will be removed from the Recycle Bin. I use this feature all the time because I like to leave files in the Trash/Recycle Bin in case I might need them but I listen to and watch a lot of podcasts and they are quite large files so I like to get rid of those files right away.

But never fear, I developed a solution for my use which I will share with you

I will give you 2 ways to remove files from it. If you are a Mac and Unix novice, skip solution 1 as it can be rather dangerous.

Solution 1. The Trash on the Mac is a hidden folder under your user directory, named .Trash. If you go into that folder in the Terminal you can remove files using the Unix rm (for remove) command. So if you are brave, open the Terminal and type the following:

cd ~/.Trash

rm *.mp3 *.mov

and whatever other file types you want to get rid of. However, you have to be very careful with rm especially using the * wildcard which matches any characters. If you leave a space after the * by mistake (e.g. rm * .mp3) it will delete all the files in the directory (and if you mistyped ~/.Trash then you will still be in your home directory and now you are probably in big trouble).

You will probably want to write a bash script to do this.

Solution 2. I wrote an Automator script so you can select and delete the files from the Mac GUI. It’s not perfect because you can’t order the files in the listing (by size or type would be much more useful than by name which is what you get) but it’s more integrated into the Mac environment.

I call the script DeleteFromTrash and you can download it by clicking on the link.

Uncompress the archive (by double clicking on it or select Open from your download menu) and put it in your Applications folder.

Open the Trash and run the script. Delete a file from the Trash and you’ll see that file disappear from the Trash. (You don’t need to open the Trash for the script to work, this is just to show/prove that it is working on your machine.)

Now we don’t have to give up that bit of Windows functionality.