Full Help of Deleting Directories in Terminal on Mac/Windows/Linux

author Aria Ford
date Friday, September 01, 2023

Deleting files and folders is a skill that computer users must learn. If you keep all your files on all the time, in no time, those files will take a toll on your Mac's processing power, RAM, and hard drive.

Therefore, deleting files is beneficial and healthy for the computer. But how do you usually do it? Most people use the ⌘ + Delete shortcut, which works system-wide. Some users right-click on the content to be deleted and select "Move to Trash" from the menu or use the "File" option in the menu bar. However, there is another way, which is to use the delete directory function on the command line. Let's see how and why you should learn it too.

Why Choose Delete the Directory in Terminal

After moving files and folders to the Trash, you can easily recover them if you need them again. However, if you delete files or folders using the Terminal, they won't be sent to the Trash. This means you won't be able to retrieve them using the usual method on your Mac. So, why do people choose to delete files, remove folders, or delete directories using the command line?

Quick and efficient deletion: Using wildcards, you can delete multiple files, folders, and even apps efficiently.

Bypassing error messages: Terminal allows you to delete items that can't be deleted through common methods, bypassing any error messages.

Deleting hidden files: It's possible to delete files that are hidden in the Finder on your Mac. These files may contain settings for certain applications or parts of macOS, and these files contain a dot (.) before their file names.

Helpful in unresponsive situations: Terminal can be useful when Finder becomes unresponsive or if you lose access to it for unknown reasons, such as when your Mac is malfunctioning.

unresponsive situations | Deleting Directories in Terminal

Part 1: [For Mac]Delete directories using the terminal

Step 1: Open Terminal on Mac

Method 1: Open through Finder.

1. Click Finder > Applications > Utilities Folder

Utilities Folder | Deleting Directories in Terminal

2. Click on Terminal twice to run it.

Also you can press Option + Command + Space to quickly open Finder and go to the "Searching This Mac" window.

Searching This Mac | Deleting Directories in Terminal

Method 2: Search for Terminal.

1. Go to Dock > Launchpad

2. Type terminal in the search field you see, and click Terminal to open it.

click Terminal | Deleting Directories in Terminal

Step 2: When the name doesn't contain space, type rm -R directoryname to delete a directory.

Step 3: If spaces are found in its name, type rm -R "directory name" to delete a directory.

Step 4: Click Return and wait.

tips Note:
  • If you want to be more cautious, you can add the "-i" flag to the delete command. The "-i" flag in the terminal command means the pause button. For example

* Delete a single file: rm -i filename.

* Delete multiple files: rm -i filename filename filename.

Finally press Return to run the command. However, you also need to enter "yes" or simply "y" to confirm the deletion this time.

Part 2: Delete Files on Mac

1. How to Delete a File in Terminal?

You can delete unwanted files with the help of the "rm" command, but you need to know that files deleted in this way are not recycled into the Trash.

Step 1: Search for Terminal.

Step 2: Enter cd ~/Desktop .

Search for Terminal | Deleting Directories in Terminal

Step 3: Type rm filename to delete a single file.

Step 4: Type "file name.extension" to delete a file when its name contains one or more spaces.

Step 5: Finally, press Return to delete files. The file will be deleted immediately without you having to confirm that you want to delete it.

2. 4 Common Methods to Delete Files & Folders on Mac

In addition to using terminal commands to quickly delete files, documents, and directories, here are some of the most commonly used deletion methods to help you delete unwanted files efficiently and intelligently.

1st way: Use Macube Cleaner Software

There is always a risk of data loss when operating a terminal to delete. If you accidentally enter the wrong command, you may face systemic destruction. But thankfully, we've got suggestions for you to fix that. Macube Cleaner is a comprehensive and smart cleaning software for Mac. It can quickly scan out hidden files, large old files, and even duplicate files can be found. Moreover, Macube also has a File Shredder to help you remove malware and stubborn files. Prevent your Mac from being harassed.

Free Download Free Download

The operation method of intelligently deleting files in Mac is as follows:

Step 1: Download and launch Macube Cleaner, click Toolkit on the left column, then click "Select Files".

launch Macube Cleaner | Deleting Directories in Terminal

Step 2: Select the files you unwanted, and click "Clean".

Select the files | Deleting Directories in Terminal

Step 3: Finally, unwanted documents will be permanently destroyed.

permanently destroyed | Deleting Directories in Terminal

Macube Cleaner can not only deal with junk files, but also delete music in iTunes, or cached emails, messages, and similar photos in albums on Mac. You can use these features to free up more space on your Mac. Trust Macube, it's worth a try.

2nd way: Hold the item to Trash.

item to Trash | Deleting Directories in Terminal

3rd way: Right click on the item and select Move to Trash.

4th way: Press [Option+⌘+Delete].

select Move to Trash | Deleting Directories in Terminal

Part 3: [For Windows] Remove Directory CMD

In Windows, there are also built-in command line tools to help users perform different tasks. The two most commonly used are the command prompt (also known as CMD) and PowerShell. For now, this article will focus on CMD deleting directories.

Step 1: Open Command Prompt Windows.

1. Hold Win + S on the keyboard.

2. Type cmd or command prompt into the search box.

3. Right click on Command Prompt from the search result, and Select Run as administrator from the context menu.

4. Click Yes if you see a User Account Control window.

User Account Control window | Deleting Directories in Terminal

tips Note:
  • If you do not operate the Command Prompt tool as an administrator, you will not be able to delete certain protected files.

Step 2: Delete Folder CMD Windows

A. CMD Delete Folder

1. To delete an entire folder or directory, you need to type the "rd" or "rmdir" command.

2. Use cd to navigate to the location of the folder.

3. If the name contains any spaces, you should type rmdir foldername or rmdir "folder name".

4.Click Enter and wait.

How to delete a directory in this situation? You should add the"/s" flag to the command.

a. Type rmdir foldername /s to delete a folder/directory whose name has no space.

b. Type rmdir /s"folder name" to delete a folder/directory containing spaces in the name.

folder directory | Deleting Directories in Terminal

tips Note:
  • If the Command Prompt tool asks you whether you want to delete the folder or directory, please press “y” to confirm.

B. Delete Files with CMD (with the “del” command)

1. Guide to locating the unwanted file.

3. Delete a file by typing del filename.extension (change filename and extension to suit your case).

4. Please type del “file name.extension” if the name contains any spaces. Finally, press Enter and wait.

 name contains | Deleting Directories in Terminal

Part 4: Remove Directory Linux

How to delete an empty folder or directory in Linux?

You can delete file Linux Terminal by using the following commands:

rmdir foldername or rmdir "folder name" (use this if the name contains spaces) and then press Enter.

How to delete a folder or directory with files and sub folders?

Type rm -r foldername or rm -r "folder name" and press Enter.

That's all about removing a directory Linux.

Part 5: Recover Deleted Data on Mac/Windows

You can recover files moved to Trash or permanently deleted using Mac Terminal. However, this command line tool cannot recover data deleted using the above "rm" command. Equally, files, folders or directories deleted using CMD commands will not be sent to the Trash. Therefore, you should turn to a powerful data recovery software that supports both Mac and Windows - Eassiy Data Recovery.

Eassiy Data Recovery is a software application designed to assist in the retrieval of missing, deleted, or formatted files from a range of storage devices, including hard drives, USB drives, and memory cards. It offers both quick and deep scanning modes, as well as preview and filter capabilities, enables users to recover various file types with up to 98.6% success rate. With its user-friendly interface, the software is compatible with both Windows and Mac operating systems, and provides clear step-by-step instructions for efficient data recovery.

Free Download Free Download Free Download Free Download

Step 1: Download and launch Eassiy Data Recovery, select the type of data you want to recover and the hard drive you want to scan.

Eassiy Data Recovery1 | Deleting Directories in Terminal

Step 2: Eassiy Data Recovery offers two scan modes:Fast Scan and Deep Scan. Quick Scan automatically starts when the software starts scanning, so we recommend using it to recover recently lost data. Then check the scan results by looking at the type and path and selecting the listed files.

Eassiy Data Recovery2 | Deleting Directories in Terminal

If you are not satisfied with the results, run Deep Scan to find more, but it may take longer.

Step 3: Use the search bar to locate files by name or path. Finally click "Recover" to recover the files.

Eassiy Data Recovery3 | Deleting Directories in Terminal

So, as you can see, Eassiy Data Recovery is reliable and easy to operate, which can help users recover lost data. Its powerful scanning automation and easy interface make it an excellent choice for anyone who needs to get their lost data back.

Conclusion:

After reading this article, you must know how to use the terminal or other common methods to delete directories. If you want to know more about deleting files, log in to Macube Cleaner official website, and you can read more useful articles for free.