The Terminal application on your Mac provides you with a tool that has the power to do many things, including things you might normally do from your desktop. Emptying the trash is one of those things, and you can do this using the rm command, as shown below.
rm ~/.Trash/*
The above command will work very easily on older machines, but for newer macOS, you will first need to give the Terminal application full disk access. Otherwise, you will need to delete files from the trash specifically by name.
My name is Eric, and as a software engineer, I always look for alternative ways to do things. Emptying your trash from the Terminal applications can solve different problems or could be more convenient. In any case, I can show you how to do this.
Whether you’re looking to remove a specific file or all of the files, keep reading below, and I will show you what you need to do to be able to empty your trash on Mac via Terminal.
Contents
Set Up Full Disk Access for Terminal
In older versions of macOS, you could easily navigate to the .Trash folder or just remove everything from the .Trash folder with the rm ~/.Trash/* command as shown above, but more recent versions of macOS have protected this directory making the task a little more complicated.
We first need to allow the Terminal Application full disk access to make this task much easier. This will remove some built-in security your mac has from user error and malware, so once you have completed the task, I recommend changing the setting back to its default.
If you are not comfortable with doing this, I will show an optional method for removing files from the .Trash folder. However, it is slightly more difficult because, without full disk access, you cannot view the directory’s contents from Terminal.
To proceed with the preferred method of giving Terminal full disk access, use the following steps.
Step 1: Close your Terminal application.
Make sure all instances of Terminal are closed. You will need to start a new instance once you change the setting.
Step 2: Open your Mac’s System Settings on the desktop.
Click on the Apple symbol in the upper left corner of the screen and select System Settings.
Step 3: Select Privacy & Security and then Full Disk Access.
In the pane on the left side of the System Settings window, click on Privacy & Security and then click on Full Disk Access in the main window.
Step 4: Turn on Full Disk Access for Terminal.
Click on the switch to turn on Full Disk Access for the Terminal Application.
The Terminal application will now have full disk access, and you will be able to easily view and remove files from the .Trash directory. It would be best if you left this window open so that you can turn this off once you have finished emptying your trash.
Emptying All Trash
Once you have completed the steps above and given the Terminal application full disk access, you are ready to empty your trash. If you would like to get rid of all files from the Trash, follow the steps below but if there are just specific files you want to get rid of, see the next section.
Step 1: Open Terminal
Open the Terminal application using your preferred method.
Step 2: Remove all files and folders from the .Trash folder
We will use the rm command with the -rf parameters. The r tells it to remove items recursively, so if there are directories there, it will remove everything inside them. The -f parameter forces the removal of the items.
rm -fr ~/.Trash/*
Type y to answer yes and confirm the removal of the files from the .Trash directory. You should now see that the .Trash directory is empty, and if you look at the Trash on your desktop, it will show that it is empty as well.
Be very careful when using this command and either copy and paste it or ensure that you type it correctly to ensure you do not delete anything you don’t want to delete.
Emptying Select Files
If you only want to remove specific files from the trash, you can also do that. You can use the rm command with the specific file. Use the steps below to find and remove the files you wish to empty from the trash.
Use the cd command as shown below to go into your trash folder.
cd ~/.Trash
Step 2: List the contents of the Trash folder.
Use the ls command to see what files are in the Trash folder and look for the ones you would like to remove.
ls -la
Step 3: Select and copy the name of the file.
Select or highlight the name of the file you wish to get rid of. Then right-click on it and click on copy. For my example, I want to remove the file called test123.exe from the trash.
Step 4: Type the rm command.
Type the rm command and a space after it. Do not hit return yet. We will be pasting the filename after it in the next step.
rm
Step 5: Paste the filename after the rm command.
Step 6: Hit Return
Hit the return key to delete the file. You should no longer see the file if you run another ls command. Also, if you look at the trash on your desktop, the file should now be gone.
You can repeat this process for any other files that you may wish to get rid of from the trash. Also, remember that if the file you want to remove has spaces, you should enclose the file name in quotation marks after the rm command. For example:
rm “Untitled document.pdf”
Turning Off Full Disk Access
Once you have completed the cleanup of your .Trash folder using Terminal, you should turn full disk access for Terminal off. This is not required, but since it is a default setting of your macOS, it is a good idea. Just follow the steps below.
Step 1: Go back to the settings window.
Go back to the settings window you left open in the Full Disk Access section above.
Step 2: Click on the switch for the Terminal application.
Click on the switch next to Terminal to turn off Full Disk Access.
Step 3: Exit Terminal.
You will need to exit the Terminal application for the setting to take effect. You will be given the option to quit Terminal and reopen it if you want.
Without Full Disk Access
If you are uncomfortable with the Full Disk Access setting for Terminal, there is a way that you can remove files from the trash without enabling this setting. You will need to use the file’s full path and full name to do so.
The easiest way is to drag and drop the file from the Trash on your desktop to your terminal window. Let’s take a look at this method below.
Step 1: Open the Trash on your desktop.
Step 2: Open Terminal
Open the Terminal application using your preferred method.
Step 3: Type rm and space in your Terminal window.
Type the rm command followed by a space in your Terminal window but do not hit the return key yet.
rm
Step 4: Select the file in the Trash on your desktop.
Step 5: Drag the file from Trash and drop it on the Terminal window.
Step 6: Hit enter, and the file will be removed from the Trash.
If needed, you can drag multiple files or all of the files from the Trash to the Terminal window before you hit enter.
Use Caution
Be sure to use caution when doing any of the procedures above. Using the rm command will permanently delete files and folders, so you want to ensure that you are removing files you want to get rid of.
You also want to ensure you type or copy the commands correctly so that you do not accidentally delete something you don’t want to. It’s always good to back up your system using Time Machine before doing things like this.
FAQs
Below are a few questions often asked when discussing emptying the Trash on your Mac.
Is there any way to get the file back once I delete it from the Trash?
Using the rm command permanently deletes files and folders, so they are gone for good once you use it. Technically you could recover them from a backup such as Time Machine if you needed to, and you have backups enabled and available.
Is there any danger to giving Terminal Full Disk Access?
Turning on Full Disk Access will not cause any issues, but it is a security measure. It helps prevent you from accidentally removing files and causing damage to your system and can protect against malware. This is why I recommend turning it off once you are done with the steps above.
What if I get a message saying a file is in use?
This means a file was probably still in use when you first deleted it. You can try closing all of your applications to see if that solves the problem, but the easiest way to fix the problem is to reboot your machine, which should take care of the issue.
Conclusion
You can use the rm command to Empty your trash by removing files from your ~/.Trash directory in Terminal. Providing full disk access to Terminal makes this process much easier, but I do recommend disabling this once you have completed the process.
Let me know if you have any questions or comments. I would love to hear from you!
Ben
Thanks for the article Eric.
Tom Weis
I tried rm ~/.Trash/* . It does’t work. All I get is “no matches found: /Users/tomweis/.Trash/*”. Items are still stuck in the trash and refuse to delete.
Eric
Hi Tom,
This is the message that is usually seen when Terminal does not have full disk access. Have you turned on Full Disk Access for the Terminal application? If you have not, make sure you follow steps 1 through 4 above under Setup Full Disk Access for Terminal. Also, ensure that you close the Terminal application and then restart it after you have given Terminal full disk access. Terminal needs to be restarted before the setting takes effect. I hope this helps. Let me know if it still does not work for you.