How-To

How to delete stubborn “in use” and locked files

Most of the time, taking out the Trash is easy: simply Control-click the Trash icon in your Mac’s Dock and select ‘Empty Trash.’

But from time to time, you may run into problems.

In this article, I’ll show you how to delete any file, folder or application, even if the item in question is locked, currently in use, or you lack the permissions required to send that item to the Trash.


File in use? Track down the app that’s responsible

If you try to empty the Trash and receive a warning that one (or more) files are currently in use, then you’ll need to close all the applications that are using that file.

This may sound straightforward, but if you’re unsure what these applications are, then you’ll need to do some digging:

  • Launch your Mac’s Terminal application (Applications/Utilities/Terminal).
  • Type the following command into the Terminal, followed by a space – but don’t press the ‘Enter’ key on your keyboard:

lsof

  • Open the Trash, find the item that you want to delete, and then drag and drop it into the Terminal window.
  • Press the ‘Enter’ key on your keyboard.
  • The Terminal will now display a list of all the apps and processes that are using this file. You’ll need to close every item that appears in this list.

Closing an application is typically straightforward, but if the application refuses to close then you may need to force quit it:

  • Select the ‘Apple’ logo in your Mac’s menu bar.
  • Choose ‘Force Quit…’
  • Select the application that’s refusing to close.
  • Click ‘Force Quit.’

To close a process, open macOS’ Activity Monitor app (Applications/Utilities/Activity Monitor). Find the process in question, and then click the little ‘Quit’ icon in Activity Monitor’s upper-left corner.

After closing all the applications and processes that were using this file, you should be able to delete the file, as normal.

How to unlock a locked file

It’s impossible to send a locked file to the Trash. If you’re encountering a “file locked” error, then you’ll need to unlock that file before you can delete it:

  • Control-click the file in question.
  • Select ‘Get Info.’
  • Click to expand the ‘General’ section.
  • Deselect the ‘Locked’ checkbox.

You should now be able to send this file to the Trash without any issues.

Give yourself permission: Deleting protected files

Often, there’s a good reason why you don’t have permission to delete an item. Perhaps the file is owned by someone else who shares your machine, or maybe it’s a system file that you really shouldn’t be touching.

Whenever your Mac warns that you have insufficient privileges to delete a file, you should pause and question whether you should even be messing around with this file in the first place.

If you do decide to go ahead, then you can give yourself permission to delete this file:

  • Control-click the file.
  • Select ‘Get Info.’
  • Click to expand the ‘Sharing & Permissions’ section.
  • Find your username, open its accompanying ‘Privilege’ dropdown menu, and then select ‘Read & Write.’

You should now be able to send this file to the Trash, and empty the Trash as normal.

Empty the Trash from the Terminal

If you’re unsure why the Trash is refusing to empty, then you may be able to resolve this problem by emptying the Trash from your Mac’s Terminal:

  • Open a new Terminal window (Applications/Utilities/Terminal).
  • Type the following command into the Terminal, followed by a space – but don’t press the ‘Enter’ key:

sudo rm -R

  • Open your Trash can.
  • Select all the files that you want to delete, and then drag and drop them into the Terminal window.
  • Now you can press the ‘Enter’ key on your keyboard.
  • When prompted, enter your administrator password.
  • Press the ‘Enter’ key.

Delete any file, instantly

When you delete an item, macOS’ default behaviour is to send that item to the Trash, rather than deleting it immediately. You’ll then need to either empty the Trash manually, or wait for the Trash to empty automatically (assuming that you’ve set the Trash to empty periodically based on a schedule).

While this does give you the opportunity to change your mind and recover a file that you sent to the Trash by accident, if there’s a file that you definitely want to see the back of, then you can delete it immediately, rather than simply sending it to the Trash.

  • Select the item that you want to delete.
  • Use the ‘Option+Command+Delete’ keyboard shortcut.
  • Read the onscreen warning, and if you’re happy to proceed, then click ‘Delete.’

Before you go

After spending over 20 years working with Macs, both old and new, theres a tool I think would be useful to every Mac owner who is experiencing performance issues.

CleanMyMac is highest rated all-round cleaning app for the Mac, it can quickly diagnose and solve a whole plethora of common (but sometimes tedious to fix) issues at the click of a button. It also just happens to resolve many of the issues covered in the speed up section of this site, so Download CleanMyMac to get your Mac back up to speed today.

mac-pc

About the author

Jessica Thornsby

Jessica Thornsby is a technical writer based in Sheffield. She writes about Android, Java, Kotlin and all things Apple. She is the co-author of O'Reilly's "iWork: The Missing Manual," and the author of "Android UI Design," from Packt Publishing.

Add Comment

Click here to post a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.