How to delete a directory depends on your operating system and whether the folder is empty
A directory is a folder that holds files and other folders. Deleting one is straightforward on Windows, Mac, and Linux, but the steps differ slightly between systems. Most of the time, you can right-click the folder and choose delete. If the folder contains files or other folders, your computer will ask you to confirm — this is a safety step to prevent accidental loss. Once you delete a directory, it goes to your Recycle Bin (Windows) or Trash (Mac and Linux), where you can recover it for a limited time if you change your mind.
The key difference between systems is where deleted folders go and how you recover them. Windows stores deleted items in Recycle Bin until you empty it. Mac uses Trash. Linux file managers also use Trash, though the command line works differently. In all cases, you can restore a deleted directory as long as you have not emptied the bin or trash — but once you do, recovery becomes much harder without specialized tools.
Key Takeaways
- On Windows, right-click a folder and select Delete to move it to the Recycle Bin, where it stays until you empty the bin.
- On Mac, drag a folder to the Trash or right-click and select Move to Trash; it remains recoverable until you empty the Trash.
- On Linux, use the file manager to right-click and delete, or use the command line with the rm -r command for faster removal.
- Deleting a directory removes the folder and everything inside it at once, so double-check the folder contents before confirming deletion.
- You can recover a deleted directory from Recycle Bin or Trash as long as you have not emptied it, but recovery becomes impossible once the bin is cleared.
Deleting a directory on Windows
On Windows, open File Explorer and navigate to the folder you want to delete. Right-click the folder name and select Delete from the menu. The folder moves to your Recycle Bin. If the folder contains files or subfolders, Windows will ask you to confirm the deletion — click Yes to proceed.
If you want to bypass the confirmation step and delete permanently without sending to Recycle Bin, hold Shift while right-clicking, then select Delete. This removes the folder immediately and does not send it to Recycle Bin, so use this method only when you are certain you want the folder gone. For most everyday deletions, the standard right-click method is safer because you can recover the folder from Recycle Bin if you realize you need it later.
Deleting a directory on Mac
On Mac, open Finder and locate the folder you want to delete. You can drag the folder directly to the Trash icon in your Dock, or right-click the folder and select Move to Trash. Either method moves the folder to Trash, where it remains until you empty the Trash manually.
If you want to delete permanently without sending to Trash, hold Command and press Delete after selecting the folder. This removes it immediately. Like Windows, this is permanent and cannot be undone, so only use this method when you are absolutely certain. For routine deletions, moving to Trash is the safer choice because you can drag the folder back out of Trash if you change your mind.
Deleting a directory on Linux
On Linux, the method depends on whether you use a graphical file manager or the command line. In a file manager like Nautilus (GNOME) or Dolphin (KDE), right-click the folder and select Move to Trash or Delete. The folder moves to Trash, where it stays until you empty it.
If you use the command line, open a terminal and type rm -r foldername, replacing foldername with the actual name of the directory. The -r flag tells the system to delete the folder and everything inside it recursively. This method deletes immediately without sending to Trash, so be certain of the folder name before pressing Enter. If you want a confirmation prompt before deletion, use rm -ri foldername instead — the i flag asks you to confirm each file or subfolder before removing it.
What happens when you delete a directory with files inside
When you delete a directory that contains files or subfolders, your operating system removes the entire folder structure at once. You do not need to empty the folder first. Windows, Mac, and Linux all handle this the same way: one deletion action removes the parent folder and everything nested inside it.
This is why it is important to check the folder contents before confirming deletion, especially if the folder has been sitting on your computer for a while and you are not sure what is in it. Open the folder, scan the file list, and make sure nothing inside is something you need to keep or back up elsewhere. Once you confirm the deletion, all those files are gone from their original location — though they remain in Recycle Bin or Trash until you empty it.
Recovering a deleted directory from Recycle Bin or Trash
If you delete a directory using the standard method (right-click and delete), it goes to Recycle Bin on Windows or Trash on Mac and Linux. You can recover it as long as you have not emptied the bin. On Windows, open Recycle Bin, right-click the folder, and select Restore. The folder returns to its original location with all contents intact.
On Mac, open Trash, right-click the folder, and select Put Back. On Linux, open Trash in your file manager, right-click the folder, and select Restore or Move Out of Trash. The exact wording varies by file manager, but the action is the same. Once you empty Recycle Bin, Trash, or use permanent deletion, recovery is not possible through these built-in tools.
Permanent deletion and data recovery services
When you delete a directory using standard methods, the folder name and file list are removed from your operating system's view, but the data itself may remain on your hard drive until that space is overwritten by new files. This is why data recovery services can sometimes retrieve deleted folders — they scan the drive for remnants of deleted files.
If you want to make deletion more permanent, some operating systems offer secure deletion options. On Windows, third-party tools like Eraser can overwrite deleted files multiple times, making recovery much harder. On Mac, you can use the Secure Empty Trash feature in some older versions, though newer Macs handle this differently. On Linux, the shred command overwrites a file multiple times before deletion. For most everyday use, standard deletion is sufficient, but if you are deleting folders containing sensitive information, these extra steps add a layer of protection.
Frequently Asked Questions
Can I undo a deletion if I already emptied Recycle Bin or Trash?
Once you empty Recycle Bin or Trash, the folder is no longer recoverable through your operating system. Data recovery services exist, but they are expensive and success is not may provide. The best practice is to check Recycle Bin or Trash before emptying it to make sure you did not delete something by mistake.
What does the -r flag do in the Linux rm command?
The -r flag stands for "recursive" and tells the system to delete the directory and everything inside it, including subfolders and files. Without this flag, rm will not delete directories, only individual files. Always use rm -r when deleting folders from the command line.
Is there a way to delete a directory without confirming?
Yes, but it is risky. On Windows, hold Shift and click Delete. On Mac, hold Command and press Delete. On Linux, use rm -r foldername without the i flag. These methods skip confirmation and delete immediately, so only use them when you are absolutely certain about the folder you are removing.
Can I delete a directory if a file inside it is open or in use?
On Windows and Mac, the operating system usually prevents deletion if a file is open. You will see an error message. Close the file first, then try deleting again. On Linux, the command line may allow deletion even if a file is in use, but the file remains on disk until the program using it closes.
What is the difference between deleting and moving to Trash?
Deleting with standard methods moves the folder to Recycle Bin or Trash, where it stays until you empty the bin. The folder is hidden from your normal file view but still recoverable. Permanent deletion (Shift+Delete on Windows, Command+Delete on Mac, or rm on Linux) removes it immediately without sending to Trash, making recovery much harder.