How to Delete Files Completely in Mac Terminal?

Kartik Wadhwa Written by Kartik Wadhwa
Updated on
Sep 26, 2026

Finder makes deleting files simple, but sometimes you need Terminal to remove a file or folder by its exact path on Mac. The Mac Terminal delete file command can remove data directly without moving it to the Trash, which makes it fast but also less forgiving.

A wrong path can remove something you intended to keep. This guide explains how to delete files and remove directories in Terminal, what the common rm options do, and how to avoid mistakes when using them.

Quick Answer

  • How to Delete Files in Mac Terminal?

    Use the rm command followed by the file path, such as rm ~/Desktop/example.txt. Use rm -i if you want Terminal to ask for confirmation before deleting the file.

  • How to Delete a Directory in Terminal?

    Use rmdir for an empty directory. To delete a directory and everything inside it, use rm -r. For example, rm -r ~/Desktop/OldFolder.

Why Use Terminal to Delete Files on Mac?

For most everyday deletions, Finder is the safer choice. Select a file, press Command + Delete, and macOS moves it to the Trash. You can recover the file from the Trash until you empty it.

Terminal takes a more direct approach. The rm command removes a file from its location instead of sending it to the Trash. This can be useful when you are working with files by their exact path, managing large directory structures, or prefer using the command line.

The trade-off is that deleting a folder with Terminal gives you less room for mistakes. Always check the path before pressing Return, especially when using commands such as “rm -r” or “rm -rf”.

How to Delete Files and Folders Completely Using Mac Terminal?

To delete a file or remove a folder from Terminal, you need to open Terminal from Applications > Utilities, or search for it using Spotlight. Then you need to run different commands for different situations. 

1. Delete a File

The rm command is used to remove individual files. The basic syntax for deleting a file is: “rm /path/to/file”.

For example:

rm ~/Desktop/example.txt

Delete a file in Terminal

You can also use an absolute path:

rm “/Users/yourname/Documents/example.txt”

The “~” symbol represents your home folder, so it can make paths shorter. If the command succeeds, the file is removed from its location rather than moved to the Trash.

If you want Terminal to ask for confirmation before deleting the file, use -i:

rm -i ~/Desktop/example.txt

This is a useful option when you want an extra check before deleting completely with Mac Terminal.

2. Delete an Empty Folder

Now let’s see how to delete a directory in Terminal on a Mac. To remove an empty directory, use rmdir:

rmdir ~/Desktop/OldFolder

Delete an empty folder in Terminal

Unlike rm -r, rmdir only removes empty directories. If the folder contains files or other folders, the command fails instead of deleting its contents. 

That makes rmdir a useful option when you want an additional safeguard against accidentally removing everything inside a folder.

3. Delete a Folder and Its Contents

To remove a directory in Mac Terminal along with its files and subfolders, use the recursive option:

rm -r ~/Desktop/OldFolder

The -r option tells rm to work through the directory and its contents before removing the directory itself. Because the rm command in Mac Terminal can remove an entire directory tree, verify the folder path carefully before running it.

4. Force Delete Files and Folders

The -f option tells rm to force removal and suppress certain errors, including errors for files that don’t exist. 

For an individual file: 

rm -f ~/Desktop/example.txt

To delete a folder in Terminal and everything inside it:

rm -rf ~/Desktop/OldFolder

Here. -r means recursive, while -f means force. You may see rm -rf described as a force-delete command, but it isn’t a universal way to bypass every macOS restriction. Permissions and system protection can still prevent some operations.

More importantly, don’t use rm -rf on an unfamiliar path just because you want to remove a stubborn file or folder. 

5. Delete Files With Spaces in Their Names

If a file or folder name contains spaces, enclose the path in quotation marks:

rm “Project Notes.pdf”

You can also escape each space with a backslash:

rm Project\ Notes.pdf

For longer paths, quotation marks are usually easier to read:

rm “/Users/yourname/Documents/Project Files/Project Notes.pdf”

Another convenient option is to drag a file or folder from Finder into the Terminal window. macOS can insert its path automatically, reducing the chance of typing it incorrectly.

6. Delete Files When Permission is Denied

If Terminal reports that you do not have permission to delete a file, do not immediately switch to rm -rf. 

First, check the file’s permissions and ownership: 

ls -l “/path/to/file”

If you have a legitimate reason to remove the file and your account does not have the required privileges, you may need administrator privileges:

sudo rm “/path/to/file”

macOS will ask for your administrator password. Nothing appears on screen while you type the password. So, just press Return when you finish.

Use sudo carefully because it gives the command elevated privileges. An incorrect path can therefore cause a more serious mistake.

Avoid using elevated commands to remove macOS system files or folders. The System folder contains essential operating system components and should not be renamed, moved, or removed.

Final Thoughts

Terminal provides a quick way to remove files and folders completely without using Finder or the Trash. Use rm for individual files, rmdir for empty directories, and rm -r when you need to remove a directory and its contents.

The most important step is checking the path before running the command. If you are unsure, use rm -i for a confirmation prompt and avoid rm -rf unless you have verified exactly what it will remove.

Frequently Asked Questions

What command deletes a file in Mac Terminal?

Ans. Use the rm command followed by the file path: rm “/path/to/file”. For confirmation before deletion, use rm -i.

How do I delete a directory in Terminal on Mac?

Ans. Use rmdir for an empty directory: rmdir “/path/to/folder/”. To remove a directory and its contents, use rm -r.

What does the rm -rf command do on Mac?

Ans. rm -rf combines recursive deletion with force. It can remove a folder and everything inside it without the usual confirmation prompts. Always verify the path before running it. 

Can I delete files from Mac Terminal without using the Trash?

Ans. Yes, the rm command removes files directly from their location instead of moving them to the Trash.

Does deleting a file with Terminal permanently erase it?

Ans. Not necessarily, because rm removes the file from the filesystem, but it is not a secure erasure method designed to make the underlying data unrecoverable. If you are preparing an entire Mac for sale or transfer, use Apple’s supported erase process rather than manually deleting files.

Sources
Related Posts
How to Add Widget in Mac: A Step-by-Step Guide
Operating System Sep 24, 2026
How to Add Widget in Mac: A Step-by-Step Guide

Your Mac desktop can give you useful information without turning into another dashboard to manage. A weather update, calendar reminder,…

The macOS Installation Couldn’t Be Completed? Learn How to Fix It
Operating System Sep 21, 2026
The macOS Installation Couldn’t Be Completed? Learn How to Fix It

You are halfway through a macOS update when the progress bar stops, and a message says the macOS installation couldn’t…

How to Restart Bluetooth Service Windows 11? (Fix Bluetooth Issues)
Operating System Sep 18, 2026
How to Restart Bluetooth Service Windows 11? (Fix Bluetooth Issues)

Bluetooth stopped working in Windows 11? It can suddenly stop working even when your headphones, mouse, or keyboard work perfectly…

How to Fix External Hard Drive Not Showing Up in Windows?
Operating System Sep 17, 2026
How to Fix External Hard Drive Not Showing Up in Windows?

You plug in your external hard drive, wait for Windows to recognize it, and then… nothing pops up. The drive…

system service exception
Operating System Sep 14, 2026
How to Fix the System Service Exception BSOD Error in Windows

A sudden Windows blue screen can bring everything to a stop, and the System Service Exception error does not tell…

macos compatibility
Operating System Sep 09, 2026
macOS Compatibility Guide: What macOS Can My Mac Run?

Trying to update an older Mac can leave you with one simple question: what version of macOS can my Mac…

check how much ram you have
Operating System Sep 08, 2026
How to Check How Much RAM You Have on Windows and Mac?

How much RAM do I have? Not sure whether your computer has 4 GB, 8GB, 16GB, or more RAM? You…

vcruntime140 dll not found
Operating System Sep 08, 2026
VCRUNTIME140.dll Not Found: How to Fix the Error in Windows

You open an app expecting it to work, only to see a cryptic message saying: VCRUNTIME140.dll not found. In most…

Split Screen on Windows Laptops
Operating System Sep 02, 2026
How to Split Screen on Windows Laptops?

Working with two apps at once is much easier when you don’t have to keep switching between them. Windows has…