46

I have a USB drive plugged into my Mac. What I found was .Trashes was not emptied when the emptying trash (right click the Trash icon and run "Empty Trash") for the USB drive

What might be wrong? Is there any other way to empty trash the USB drive?

3
  • 10
    Interesting, emptying the trash always does so successfully for my USB drives. My only complaint about it is that often I'd like to only empty the trash on my USB drive and not have to do so for every drive on the system. Commented Jan 16, 2011 at 0:34
  • 4
    @Matthew try rm -R /Volumes/volumename/.Trashes/$UID Commented Jan 16, 2011 at 2:55
  • @Gordon Perfect, thanks! Created a one-line Applescript to run the command and it's a couple of QuickSilver keystrokes any time. Commented Jan 16, 2011 at 8:22

5 Answers 5

38

It's possible that there are files in some other user's trash. The .Trashes folder at the top of each volume has subfolders for each different user, by user ID number (e.g. user 502's trash is in .Trashes/502).
You can see if it for yourself using a command like this (replace VolumeName with your drive name):

ls -la /Volumes/VolumeName/.Trashes/
total 0
d-wx-wx-wt@  3 _unknown  _unknown   102 10 Feb 18:15 .
drwxrwxrwx@ 21 root      wheel      782 13 Feb 14:17 ..
drwx------@ 35 _unknown  _unknown  1190 13 Feb 14:18 502

Note: you might get a permissions error from this command, either because the .Trashes folder doesn't allow read access (solve this by adding sudo, e.g. sudo ls -ls ..., and entering your admin password when requested); and/or because of the privacy protections in macOS Mojave (10.14) and later (solve this by granting the Terminal access in System Preferences > Security & Privacy pane > Privacy tab > Full Disk Access category, see here for more details).

As you can see, on my USB disk .Trashes folder there's a sub foder called 502, owned by user ID 502 (for reference, my current user ID is 501). Since this user doesn't exist on my system, I see it as _unknown, and my user can't look inside of it, neither delete it. To look inside that folder we need to do it as administrator (i.e. use sudo).

If you are sure that you want to, you can delete everyone's trash by deleting the entire .Trashes folder with a command like:

sudo rm -R /Volumes/volumeName/.Trashes

Warning: as with anything involving sudo ("do as super user", i.e. system administrator) and rm -R, use this carefully. If you type it wrong, it could have ... unpleasant consequences.

5
  • The "might be in someone else's Trash" is exactly the issue I was running into. This should be better advertised!
    – cdeszaq
    Commented Nov 11, 2012 at 16:28
  • Adding the -f switch to the command will force the action. Substituting the "volumename" with "*" would allow you to connect multiple USB drives and empty all the Trash on all of them simultaneously. Don't have to connect 1-by-1 and then re-do. Commented Sep 28, 2013 at 10:25
  • 1
    It may be dangerous to run a command that involves both sudo rm and /Volumes/*/something, because it could affect even your system drive, and a typo can have bad consequences.
    – gerlos
    Commented Feb 13, 2017 at 17:51
  • This is helpful, but I got "permission denied" until I granted "Full Disk Access" to Terminal from "Security and Privacy" settings. It seems like this is a requirement for recent (Catalina onwards? I'm on Big Sur) OS versions. You got my upvote, but for the benefit of others can you please update this answer with that information? For reference: osxdaily.com/2018/10/09/…
    – firebush
    Commented Dec 25, 2020 at 21:30
  • @firebush Good point; I added notes and a link. Commented Dec 26, 2020 at 1:06
10

Usual behavior:
When you delete something off a USB drive, it is moved to a .Trashes folder on that volume. When plugged into your computer, deleted items will appear in your trash bin with everything else.

When you unplug it, items that you've deleted from that drive will no longer show up in your trash UNTIL you plug it in again. Then, you can empty the trash. It will really delete them from that drive.

If that isn't happening for you, here's my suggestion:

  1. Select the drive in your Finder sidebar.
  2. Without selecting anything else, press cmd-i (or use menu item FileGet Info).
  3. Use the Sharing and Permissions section of that window to give Everyone the permissions to Read and Write.
1
  • This should be accepted
    – zsitro
    Commented Sep 9, 2014 at 14:43
7

I don't know wether it's the best answer, but at least it's working answer.

Open the command line, cd to the USB volume (/Volumes/USB for my case), and type:

/bin/rm -rf ./Trashes/* works fine with me.
1
  • This would require the user has to go to the specific volume each time. Building on your reply, I've come up with a Bash script and AppleScript solution. Commented Sep 28, 2013 at 10:09
2

2 Solutions. 1 using Bash the other using Bash wrapped in AppleScript.

Solution #1

  1. Create a new AppleScript with /Applications/Utilities/AppleScript Editor
  2. Type the following code:

    do shell script "rm -rf /Volumes/*/.Trashes/*" with administrator privileges

  3. Save the file to somewhere convenient and run it whenever you need to clear the USB Trash
  4. This can be executed by double-clicking on it

NOTE: This will empty the Trash for all connected volumes including your internal hard disk. If you have connected 5 USB drives and a Firewire hard disk, it will empty the trash for all of them.


Solution #2

  1. Fire up your favourite text editor (mine is nano)
  2. Paste the following code into your text editor and save the file

    #!/bin/bash
    sudo rm -rf /Volumes/*/.Trashes/*

  3. Save the file to somewhere convenient with the extension .sh and then make it executable with chmod +x {filename}.sh from Terminal

  4. Run that with ./{filename}.sh

NOTE: Same note as above. This is executable from Terminal.

2

I use this script AppleScript, save it as Application :

on open these_volumes
    set t_id to user ID of (system info)
    repeat with i in these_volumes
        if (kind of (info for i without size)) is "Volume" then
            set tPath to (POSIX path of i) & ".Trashes/" & t_id
            do shell script "/bin/rm -Rf  " & (quoted form of tPath) & "/*"
        end if
    end repeat
end open

Drag/Drop Volume(s) on the application.

This script removes the items from your trash (user ID) folder on the volume. if other users use the volume this script will not delete the items from their trash folder, otherwise the script would need an administrator password to do that.


If you want to eject the volume after emptying the trash, use this script.

on open these_volumes
    set t_id to user ID of (system info)
    set volToEject to {}
    repeat with i in these_volumes
        if (kind of (info for i without size)) is "Volume" then
            set tPath to (POSIX path of i) & ".Trashes/" & t_id
            do shell script "/bin/rm -Rf  " & (quoted form of tPath) & "/*"
            set end of volToEject to contents of i
        end if
    end repeat
    if volToEject is not {} then tell application "Finder" to eject volToEject
end open
1
  • To make the applescript work, simply drag the connected device or drive to the AppleScript application and drop. You can create an alias on the dock next to the regular trash bin for convenience, by dragging and dropping the Application icon into the side-dock.
    – Tony_kenya
    Commented Feb 17, 2015 at 13:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .