Terminal Can Delete File - Mac Tutorial [2023] (2023)

Sue Wayne

Aug 04, 2023 • Filed to: Solve Mac Problems • Proven solutions

Aterminal should not be something to frighten you. Many Mac users shy away from it because, in all fairness and honesty, using it can be complicated, but that's only before you realize how simple it is to use.

One of its most important functions is deleting files, so if you're wondering how to go about deleting a file in Terminal, or maybe even several files, keep reading. There are a few basic rules about Terminal you need to understand to do this, but you'll get the hang of them soon enough.

  • Part 1: Scenarios to Delete Files via Terminal
  • Part 2: Terminal Commands to Delete Files
  • Part 3: Full Guide to Delete Files in Terminal
  • Part 4: How to Get Back Deleted Files on Mac

Part 1: Scenarios to Delete Files via Terminal

By default, your Mac comes with numerous ways to delete files, ranging from keyboard shortcuts to your Finder. Certain third-party apps can perform the action for you too.

For the majority of Mac users, deleting files using these mediums is more user-friendly than Terminal, which is arguably true. With that being said, is there a reason you should opt for the more complex option? Yes, there is.

    • For one, using Mac Terminal is faster than using Finder. By using wildcards (*, [], ?) you can quickly delete any number and size of files. Doing this also nullifies the need to open several folders and highlight all the files and then empty Trash too.
    • Many of your files can be hidden by Finder and accessing them becomes almost impossible except via Terminal. These files mostly harbor settings for particular software or sections of your macOS, and a dot (.) normally precedes their names. Your Finder probably won't show them but Terminal can.
    • Perhaps some of the most important reasons you should learn and understand how Terminal works are when your macOS gets corrupt and ceases to function. A terminal can be your trump card because, with the right commands, you can troubleshoot the problem and arrive at the best solution to it.
    • Borrowing from the above point, sometimes your macOS might still be functional but it still ends up glitches. For instance, you're not able to copy and paste files due to one error or another. A terminal can be used as a substitute until you have the time to repair the errors plaguing your Mac.
    • It's possible that after deleting your files to Trash, you would want to recover them. Terminal has this function in its large arsenal too, and with just one or two commands, you can take everything out of the Trash again.

Part 2: Terminal Commands to Delete Files

There are several commands you can utilize to your advantage. Some work better in certain situations than others, so go through the list and see which of them suite your needs the most.

    • Command: rm

This is the primary command used to delete a single file. Just type the name of the file after typing in the command; like so: rm filename

    • Command: y

This is the command to remove write-protected files. Sometimes, if the file you're trying to delete is write-protected, you will be asked for confirmation. An example is given below:

rm: remove write-protected regular empty file 'filename'?

Once you see this prompt in your Mac's terminal, type y and then hit "Enter" to remove the write-protection.

    • Command: rm filename1

This command is what you use to simultaneously delete multiple files. All you have to do is type rm followed by the name of each file; like so: rm filename1 filename2 filename3

    • Command: rm *

This is the command to match and delete multiple files. Wildcards (*) can be implemented in Terminal to match numerous files of the same type or extension and delete them. For example, if you wanted to delete multiple doc files in the same directory, type this in your Terminal: rm *.doc

    • Command: rm -i

This is the command used to confirm the deletion of each file. If, for any reason, you'd rather be prompted for a confirmation before you delete a file, use this command before typing in the name of the file. Like so: rm -i filename(s)

    • Command: -f

This is the command todelete fileswhile bypassing the prompt message. Think of it a command which uses "brute force" to get the files out of your Mac. Even if the files are write-protected, this command negates the need to input any other command. To use it, type in the command and the name of the file or files; like so: rm -f filename(s)

Part 3: Full Guide to Delete Files in Terminal

If you haven't been using Terminal to handle tasks on your Mac, you've been missing out on a lot. You basically cheat your macOS because Terminal circumvents the need for you to go through loner processes to delete files and more.

Commands like rm are exceptionally powerful in deleting files, while commands like rmdir easily get rid of directories.

Of course, with a tool so powerful, there will inevitably be risks, so you have to be careful with Terminal because you could end up doing more damage than good.

If you're still wary about using Terminal, this post will teach you easy and safe ways to delete irrelevant files while keeping the important ones safe.

Deleting Files in Terminal

Contrary to its looks, the Terminal window is actually quite user-friendly. To delete a file, justlaunch Terminal, type the rm command and then the name of the file to be deleted, and then hit "Enter/Return".

If the file is located in a particular directory-like your desktop, for instance-type this in Terminal and hit enter: cd ~/Desktop From there, just look for the file you want to delete and type rm, succeeded by the name of the file, like so: rm MyFile.rtf Hit the "Enter/Return key. The moment you do that, the file says "farewell, till we meet again." Of course, you won't be meeting it again because it's been utterly erased from your Mac. Do you see how effortless it is to use Terminal?

Are you still worried about something potentially going wrong? Well, in that case, you can resort to another, less potent command to delete your files. The main difference is, this one asks you for permission before taking action. Artificial Intelligence is a beautiful thing, isn't it?

This command is written as such: -i

You can also call this command interactive. Refer to the examples below to see what it entails:

rm -i MyFile.rtf

rm -i MyFile.rtf MyCV.rtf MyGreatAmericanNovel.rtf

Even if you type the commands up there and press "Enter", nothing will happen. The -i nullifies the action of the rm command. In your Mac's terminal, running these commands should look something like this:

Terminal Can Delete File - Mac Tutorial [2023] (2)

You won't be able to delete the files until you type yes or just y to the confirmation message you see in the image above. Remember, the whole point of using the interactive command is to exercise caution before deleting a file, so have that at the back of your mind.

Delete Directories in Terminal

A Terminal is also capable of deleting entire directories or folders, but you can't just run the usual rm command or you'll end up seeing a message like this:

Terminal Can Delete File - Mac Tutorial [2023] (3)

What this all means is, you have to make use of a different kind of command to get rid of folders: rmdir

So, let's say you wanted to delete a folder called Balloons. This is what you have to type in Terminal: rmdir Balloons Mind you, the -i flag bears no effect on rmdir, so there's no option for confirmation when deleting folders. By the way, rmdir can only delete empty folders, so if that's not what you're looking for, there's a bit more reading left for you to do down below.

Delete Absolutely Everything

The rm command has a big bad brother. It's a more powerful command written as such:

-R (or -r)

It's also known as the recursive option. Putting rm and -R together is a recipe for the TOTAL deletion of files.

When you run these commands on a folder, you're basically instructing Terminal to delete that folder into nonexistence. Your Terminal will delete the folder, the files it contains, any sub-folders that could be within the main folder, and even the files and more subfolders with the first subfolders. As you can see, the commands leave no room for escape.

Here's a practical example: If you have a heck load of archives in a particular directory, then sub-directories and files within them for good measure, it would be cumbersome to go about deleting the folders one by one, be it via Finder or even Terminal.

An easier and quicker way to do that is to just type this command in Terminal:

rm -R Archives

Fortunately, you can use -i flag with this command as a safety net.

rm -iR Archives

That's really the most important thing you need to know about deleting files via Terminal. There are many other commands, of course, but if you get the hang of these commands, you're off to a very good start.

Part 3: How to Get Back Deleted Files on Mac

You are the only one who truly knows how important your files are to you, which is why no one will blame you if, by some manner of an accident, you permanently delete files from your Mac; files that never even got a chance to get to your Trash.

There's a silver lining in every cloud though, and that silver lining isRecoveritMac Data Recovery. Even files deleted via Terminal can still be recovered using Recoverit, and that's a feat that is impossible for several other data recovery software, but not Recoverit.

With features that make it possible to recover all file types deleted or lost in any possible way you can think of, this is the only solution you need to get back deleted files and data. Here's how to use it:

Download | MacDownload | Win

Step 1: Choose a Location

    • Open Recoverit and go over the "Hard Disk Drives" category. You will see all the drives currently connected to your Mac. Select the one to be scanned (the drive where the deleted files were before you deleted them).
    • Click the "Start" button.

Terminal Can Delete File - Mac Tutorial [2023] (4)

Step 2: Scan the Location

    • The scan won't take long to complete. As a matter of fact, Recoverit comes bundled with great features that speed up the scan as much as is possible. Among them are the "File Type" and "File Path" filters. And you can safely pause the scan whenever you wish, or even stop it if that's what you want.
    • Let the software run through your drive and minutes later, you will see a window displaying a preview of all the files you deleted, regardless of how long ago it was. This window marks the end of the scan.

Terminal Can Delete File - Mac Tutorial [2023] (5)

Step 3: Preview & Recover Deleted Files

  • Once you're done with the preview window, make a selection of the files you wish to recover or simply recover everything just to be safe. Mind you, the files will be much in number because the scan will give you results of all the files ever deleted and emptied from your Trash or deleted from your Mac.
  • Click "Recover" and watch the progress as your files are recovered. They will be kept in a directory chosen by Recoverit; you can choose a different directory if you so wish.

It won't go amiss to choose a different save location for the recovered files from their original directory. The simple reason for this is when you recover deleted data back to the same directory it was deleted from, you stand a risk of overwriting the data before its fully recovered.

Recoverit Mac Data Recovery has been around for years, which should be credible proof of its efficiency and how trusted it is. Users who have tried other recovery software and then used Recoverit always state his simple fact: When it comes to data recovery, Recoverit takes the crown.

Terminal Can Delete File - Mac Tutorial [2023] (6)

Download | MacDownload | Win

Closing Words

Rarely a day goes by without you turning on your Mac and accessing your files, does it? The files could be as small as a document or as large as a video encoded in the highest of definitions.

The terminal makes it very easy to make sure none of those files, big or small, use up space in your Mac's drive. The powerful tool is a shortcut to deleting any type of file or folder regardless of whether it's hidden or not.

Should the worst happen and you end up getting rid of important files, Recoverit can step in and make things right again. Give it a try. You won't regret it.

Download | MacDownload | Win

What's Wrong with Mac

Recover Your Mac
  • Recover my trashed files.
  • Recover deleted files on Mac.
  • 3 ways to restore Mac photos.
  • Recover SD card files on Mac.
  • How to Unsend iMessage on Mac?
  • Get files from external drive.
Fix Your Mac
  • Fix grey screen at startup.
  • Ethernet issues occur | Fixed.
  • Mac won't shut down. Boot it.
  • Solve flashing question mark.
  • Fix slow WiFi after upgrade.
Delete Your Mac
  • Format your USB drive.
  • Delete APFS partition.
  • How to format APFS drive.
  • What can be cleaned on Mac.
  • Format external hard drive.
Learn Mac Hacks
  • Boot Mac into Recovery mode
  • Create a Mac recovery USB.
  • Create a Mac recovery disk.
  • Resize APFS container.
  • Install Mac on external drive.


How do I force delete a file in Terminal Mac? ›

Here's how:
  1. Navigate to Terminal on your Mac by opening a Finder window and selecting Applications > Utilities. You can also press Command+Space to open Spotlight. ...
  2. In the Terminal window, type rm and a space. Next, drag the file you want to delete into the Terminal window.
  3. Press Enter, and the file is gone forever.
Sep 20, 2022

How do I delete files on my Mac that won't delete? ›

Delete an item from your Mac or iCloud Drive

If an item is locked, you need to confirm you want to move it to the Trash, or unlock the item before putting it in the Trash. To unlock the item first, select it, choose File > Get Info (or press Command-I), then deselect the Locked checkbox.

Why I Cannot delete files from my hard drive on Mac? ›

Permission Issue of Mac

The permission settings on your Mac define who has access to your files. Permission issues could be another reason you can't delete files and folders from your external hard drive. The problem will continue if permissions are not granted.

How do I get rid of files that won't delete? ›

One is simply using the delete option, and the other one is deleting files permanently. When you can't delete a file normally, you can delete undeletable files Windows 10 by selecting the target file or folder and then press Shift + Delete keys on the keyboard for a try.

How do I force delete everything on my Mac? ›

From the Apple menu  in the corner of your screen, choose System Settings. Click General in the sidebar. Click Transfer or Reset on the right. Click Erase All Content and Settings.

How do you delete on a Macbook using commands? ›

Command-Delete: Move the selected item to the Trash. Shift-Command-Delete: Empty the Trash. Option-Shift-Command-Delete: Empty the Trash without confirmation dialog.

How to delete file that cannot be deleted with command prompt? ›

You can press Windows + R keys on the keyboard, type cmd, and press Ctrl + Shift + Enter to run Windows Command Prompt as administrator. Step 2. Then input the command line and hit Enter to force delete the file in Windows 10 with CMD. The command line is like this: del c:\users\alisa\desktop\test.txt.

How do I delete corrupted files? ›

How to delete corrupted files?
  1. Solution 1: Restart Computer and Delete Corrupted Files Using the Administrator Account.
  2. Solution 2: Close Windows Explorer and Restart Computer to Delete Corrupted Files.
  3. Solution 3: Delete Corrupted Files in Safe Mode.
  4. Solution 4: Use the CMD Command Prompt to Delete Corrupted Files.
5 days ago

How do I force delete a command? ›

Use the del Command to force delete a file

With the command prompt window open, enter the following command: del /f filename, where filename is the name of the file or files (you can specify multiple files using commas) you want to delete and then hit enter. The /f forces deletion of read-only files.

How do you hard delete files on a Mac? ›

How to Permanently Delete Files on Mac Using Shortcuts. To permanently delete a file or folder, bypassing the Trash, press Option + Command + Delete keys. To remove a file a folder to the Trash, press Command + Delete keys. To empty your Trash, use Command + Option + Shift + Delete.

Why does Mac not have delete? ›

Why are there no Delete keys on MacBooks? To save space and make the laptop smaller. And also because, as explained above, the Delete key tends to be used less than the similar Backspace key.

How do I delete a directory that is not empty in terminal? ›

To permanently remove a directory in Linux, use either the rmdir or rm command. The rmdir or rm -d command is for removing empty directories, while the rm -r command deletes non-empty directories.

How do I delete ghost files on my Mac? ›

Run the Finder app, and hold down the SHIFT key on Sierra or OPTION/ALT key on earlier systems as well as pull down the Go menu at the same time. Choose Library on the list, find and open the Caches folder. Now, you can delete caches and temporary files according to your need.

Top Articles
Latest Posts
Article information

Author: Rob Wisoky

Last Updated: 07/12/2023

Views: 5575

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.