How to Delete a Folder and Everything in It in the Terminal
rm on its own won't delete a folder. Add -r and it deletes the folder with every file and folder inside it, and add -f as well and it does that without a single question or message. In PowerShell, Remove-Item -Recurse -Force does the same.
Neither command asks you to confirm, so this guide practises on a folder it creates for the purpose, with real output from zsh 5.9, bash 3.2 and PowerShell 7.6 on macOS.
Syntax
In bash and zsh:
rm -rf <folder>
In PowerShell:
Remove-Item -Recurse -Force <folder>
| Part | What it means |
|---|---|
rm | Short for remove. Deletes files |
-r | Deletes folders too, with everything inside them, every level down |
-f | Never asks, and says nothing when the name doesn't exist |
Remove-Item | PowerShell's command for deleting files and folders |
-Recurse | Deletes everything inside the folder too |
-Force | Also deletes hidden and read-only files |
<folder> | The folder to delete |
The macOS manual page, man rm, describes -R as Attempt to remove the file hierarchy rooted in each file argument., and -r as Equivalent to -R. For -f: Attempt to remove the files without prompting for confirmation, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error.
Microsoft's documentation for Remove-Item describes -Recurse: Indicates that this cmdlet deletes the items in the specified locations and in all child items of the locations. And -Force: Forces the cmdlet to remove items that can't otherwise be changed, such as hidden or read-only files or read-only aliases or variables.
The Example
You create a practice folder, old-project, with a file in it and a drafts folder holding another file, and then delete all of it.
Step 1: Create a Folder to Practise On
- bash / zsh
- PowerShell
mkdir -p old-project/drafts
echo 'Read me first' > old-project/readme.txt
echo 'An idea' > old-project/drafts/idea.txt
ls -R old-project
drafts readme.txt
old-project/drafts:
idea.txt
mkdir -p creates old-project and the drafts folder inside it. Each echo line writes a line of text into a new file, and ls -R lists the folder and every folder inside it.
New-Item -ItemType Directory -Path old-project/drafts | Out-Null
Set-Content -Path old-project/readme.txt -Value 'Read me first'
Set-Content -Path old-project/drafts/idea.txt -Value 'An idea'
Get-ChildItem -Recurse -Name old-project
drafts
readme.txt
drafts/idea.txt
New-Item -ItemType Directory creates both folders, and | Out-Null Hides the output instead of sending it down the pipeline or displaying it. Each Set-Content line writes a file, and Get-ChildItem -Recurse -Name lists everything inside the folder.
Step 2: Try It Without -r
- bash / zsh
- PowerShell
rm old-project
rm: old-project: is a directory
rm refused, and the folder is still there. Without -r, it deletes only files. Its manual: The rm utility attempts to remove the non-directory type files specified on the command line.
Remove-Item old-project
Confirm
The item at /Users/you/delete-demo/old-project has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): N
PowerShell asked first. Typing N and pressing Enter answered No, and Test-Path old-project then printed True: the folder was still there. The documentation: When you try to delete a folder that contains items without using the Recurse parameter, the cmdlet prompts for confirmation.
Step 3: Delete It with -r and -f
- bash / zsh
- PowerShell
rm -rf old-project
ls old-project

ls: old-project: No such file or directory
rm -rf printed nothing. ls lists what's in a folder, and here it says the folder doesn't exist: both files and the drafts folder went with it. The manual's own example is the same command: Recursively remove all files contained within the foobar directory hierarchy.

bash printed the same as zsh in every step.
Remove-Item -Recurse -Force old-project
Test-Path old-project

False
Remove-Item printed nothing, as its documentation says: This cmdlet returns no output. Test-Path printed False: the folder isn't there any more.

Step 4: See What -f Hides
- bash / zsh
- PowerShell
rm -r missing-folder
echo $?
rm -rf missing-folder
echo $?
rm: missing-folder: No such file or directory
1
0
echo $? prints the exit status of the command before it. Without -f, rm named the folder it couldn't find and ended with 1, an error. With -f, it said nothing and ended with 0. The manual: The rm utility exits 0 if all of the named files or file hierarchies were removed, or if the -f option was specified and all of the existing files or file hierarchies were removed. So with -f, a mistyped name looks exactly like a folder that was deleted.
Remove-Item -Recurse -Force missing-folder
Remove-Item: Cannot find path '/Users/you/delete-demo/missing-folder' because it does not exist.
In PowerShell, -Force doesn't hide a wrong name: Remove-Item still says which path it couldn't find.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
A name with a space, not quoted: rm -rf old project | Nothing printed, and nothing was deleted: ls still showed old project | Quote the name: rm -rf 'old project' deleted it |
rm old-project without -r | rm: old-project: is a directory, and the folder stays | Add -r |
Remove-Item old-project without -Recurse | PowerShell asks Are you sure you want to continue? | Add -Recurse |
In the first row, rm looked for two items, old and project. Neither exists, and -f kept quiet about both.
FAQ
How do I see what rm deletes?
Add -v. rm -rv old-project printed each item as it went:
old-project/drafts/idea.txt
old-project/drafts
old-project/readme.txt
old-project
The manual: Be verbose when deleting files, showing them as they are removed.
Can it ask me before it deletes?
Yes. In bash and zsh, use -I in place of -f: rm -rI old-project asked recursively remove old-project?, and answering n kept the folder. The manual: Request confirmation once if more than three files are being removed or if a directory is being recursively removed.
In PowerShell, -WhatIf shows what would happen without doing it. Remove-Item -Recurse -Force old-project -WhatIf printed What if: Performing the operation "Remove Directory" on target "/Users/you/delete-demo/old-project"., and the folder stayed. The documentation: Shows what would happen if the cmdlet runs. The cmdlet isn't run.
Conclusion
rm -rf old-project deleted the folder together with both files and the drafts folder inside it, and Remove-Item -Recurse -Force old-project did the same in PowerShell. Check the name before you press Enter: with -f, a wrong name deletes nothing and says nothing.
Additional Resources
man rmin your terminal: every option ofrmon macOS.- Remove-Item (Microsoft Learn):
-Recurse,-Forceand-WhatIf.
