Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A relatively safe method of deleting trashed locked files System
Recently I found myself wanting to get rid of Windows Media Player 9. I used AppZapper to get all the application components in the trash, but then I was unable to delete it because files (specifically .htm files) deep within the contents of the app are locked. So after a little research, I came across this fairly simple solution and figured I'd share it:

Warning: Typographical error or misuse of the following rm -rf command can result in serious data loss. Insertion of a space in the wrong place could result in the complete deletion of data on your hard disk, for example. You may wish to copy and paste the commands below into a text editor to verify spacing. Follow these steps to delete Trash for the logged-in user:
  1. Use a program like AppZapper to get all WMP components in the trash.
  2. Open the Terminal application, in /Applications -> Utilities.
  3. In Terminal, type sudo rm -rf[space]. Don't type [space] literally; just press the space bar on the keyboard. Do not press Return.
  4. In Finder, open your Trash.
  5. Choose Select All from the Edit menu.
  6. Drag the selection (all) from the Trash window into the Terminal window. This causes the Terminal window to automatically fill in the name and location of each item in your Trash.
  7. Press Return.
Now your computer will be free from Windows Media Player. Hope this helps!

[robg adds: As noted in a previous hint, if you hold down Option before you select Finder: Empty Trash, then locked items will be deleted (or just use the Dock's contextual menu, apparently, as noted in a comment to that hint). But the above method may be useful if you have a really stuck file in the trash. By using drag and drop, you can use sudo rm -rf in a relatively safe way -- it will only act on those items you specifically dropped onto the command in Terminal. It's still a very dangerous command, of course, but used in this manner, it's about as safe as possible.]
    •    
  • Currently 2.33 / 5
  You rated: 4 / 5 (3 votes cast)
 
[8,947 views]  

A relatively safe method of deleting trashed locked files | 15 comments | Create New Account
Click here to return to the 'A relatively safe method of deleting trashed locked files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A relatively safe method of deleting trashed locked files
Authored by: JadeNB on Aug 24, '06 08:58:10AM

If you want to wipe out your whole Trash (as this hint suggests), you can also do

cd /.Trashes; sudo rm -rf *

without any dragging from the Finder.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: macgruder on Aug 24, '06 09:33:27AM

cd /.Trashes

Are you sure about this?

Cd'ing into the .Trashes at the root level, I don't think will get rid of user's trash.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: macgruder on Aug 24, '06 10:02:01AM

Ah yes. Sorry, you're right there! Ignore the above.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: rhowell on Aug 24, '06 09:00:55AM

This is a good hint for those new to the Unix command-line. However, newcomers may need to know what the final, missing step is:

...

7. Hit Return

8. You will be prompted for your account password. This is the password you provided when you first set up your account in OS X. As you type it in, no text will appear in the Terminal. That's OK. Hit return after typing your password.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: macgruder on Aug 24, '06 09:58:06AM
I'm not overly excited about this hint. I certainly do not recommend mucking about with rm -rf and * in combination with copying and pasting into the terminal. If you're going to do it this way is much much safer:

$ cd
$ cd .Tras                   [hit the tab key here, Tras will expand to Trash]
$ echo *                   [if you get an output that does NOT reflect the contents of the trash STOP right there]
$ sudo rm -rf !$                [will delete the output from the above echo]
enter password as explained above

[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: macgruder on Aug 24, '06 10:03:53AM

The above will delete your own Trash from your local disk.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: jaaronp on Aug 24, '06 10:20:56AM

Given the potential badness of doing things like running rm -rf as root an alternative may be helpful.

Specifically, I would try first unlocking all of the files in the Trash using

$ sudo chflags -R nouchg,nouunlnk,nosunlnk,noschg ~/.Trash

Now the Finder locks should all be clear and you can empty your trash as normal.


See man chflags for details.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: ether on Aug 24, '06 11:09:43AM
In Terminal, type sudo rm -rf[space]. Don't type [space] literally; just press the space bar on the keyboard. Do not press Return.
If you type the above literally, including the period, you are in danger of deleting your current directory as well as what's in the trash. You want to type:
sudo rm -rf
followed by a space, then the drag.

[ Reply to This | # ]
A truly safe method
Authored by: SOX on Aug 24, '06 11:24:15AM

Yes rm is like a table saw. If you are careful you get to keep your fingers. but one teeny tiny moment of inattention and .....

So here's a safer kludge.

Simply move (sudo mv) the files to /tmp
they won't be deleted till the next time you reboot. But they will get deleted for sure.

Now if you really want to delete them, put them in a subdir of /tmp and then overwrite that subdir. But that gets back to some of the same dangers as rm.




[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: hamarkus on Aug 24, '06 04:06:17PM

As mentioned probably multiple times already on this website, the first thing when a file cannot get deleted is to try 'Secure Empty Trash'. It carries basically no risk of deleting other files (but in case you dragged the wrong files into the Trash, there will be no way of getting them back).

Always worked for me. Your milage may vary.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: qwerty denzel on Aug 25, '06 12:53:42AM

That is usually my preferred method. It may take longer for large files, as the files are overwritten by random data.

Holding down the option key whilst selecting the menu item or performing the key command allows locked files to be deleted (which I always do by habit), but I seem to remember it not working for files that are still open or being used, while securely emptying handles them without a hitch.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: EelBait on Aug 24, '06 08:53:14PM

Sort of a corollary to the above comments is how to really protect a file. If you lock a file using the Finder's "get info" window, you are really setting the "uchg" flag and is equivalent to chflags uchg filename. The only way to remove a file such is to first clear the flag, by unchecking the "locked" flag in the Finder, or by chflags nouchg filename in the terminal.

Now, if you REALLY want to protect a file, you set the "schg" flag via chflags schg filename. Once again, the file can only be removed if you first clear the flag. This is the fun part. You can only remove the schg flag while in single-user mode. Not even root can remove this flag.

To do this you need to reboot while holding down "Command-S" until you arrive at the command prompt. Following the instructions you type mount -uw / to make the hard drive writable. Then you "cd" to the location where your file is and type chflags noschg filename. Then you may delete the file.

This is great way to make certain critical files impervious to modification in a hostile network environment.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: The_Decryptor on Aug 25, '06 06:01:55AM

I just do "Secure Empty Trash", it nukes any locked files.



[ Reply to This | # ]
A relatively safe method of deleting trashed locked files
Authored by: alan-trewartha on Aug 25, '06 06:15:39AM

if you are going to resort to rm-ing, one extra step you can take to fail-safe, is to have a separate "ownerless" partition, a "Work" partition, where all your documents are kept. that way emptying the trash of files from that partition won't take a sudo, and you won't accidentally delete system files.

of course you still run the risk of deleting other document files by accident.



[ Reply to This | # ]
You may not want to delete WMP 9 quite yet
Authored by: leebennett on Aug 30, '06 08:38:55AM

This isn't directly related to the original hint, but because the submitter mentioned Windows Media Player 9 for Mac, I'm chiming in quickly to point out ya'll may want to hang on to it a bit longer, even if you're on an Intel Mac. There are still quite a number of WMV streams to which Flip4Mac it not yet able to connect.



[ Reply to This | # ]