The Windows DEL command (also known as ERASE) removes one or more files from Command Prompt. When you are cleaning temp folders, pruning build artifacts, or wiping test outputs, it is faster — and more scriptable — than clicking through File Explorer. Used carelessly, it is also one of the easiest ways to lose work. This guide focuses on safe patterns first.
For the official reference, see Microsoft Learn’s del command.
What does DEL do?
del notes.tmp
That deletes notes.tmp from the current directory. Relative paths resolve from where you are now. Confirm that with cd before you delete anything important.
erase is the same command with a different name:
erase notes.tmp
Confirm before you delete: /P
The single most important safety flag is /P. It asks you to confirm each file before removing it:
del /P *.tmp
CMD prints something like Delete (Y/N)? for every match. Answer Y to delete that file, N to skip it. Use /P whenever you are not 100% sure the wildcard is right.
Quiet mode vs prompts: /Q
By default, deleting a wildcard pattern can trigger a “Are you sure (Y/N)?” prompt. To skip that confirmation (common in scripts):
del /Q *.log
/Q means quiet. Pair it with a tight wildcard you have already tested with dir first:
dir *.log
del /Q *.log
Never start with /Q on a broad pattern like *.* until you have previewed the match list.
Force read-only deletes: /F
Read-only files normally refuse to delete. /F forces removal of read-only attributes and deletes the file:
del /F locked.txt
Useful for cleaning build caches. Dangerous if you did not mean to touch that file — combine with /P when exploring:
del /F /P *.bak
Include subfolders: /S
/S deletes matching files in the current folder and every subdirectory:
del /S *.tmp
This is powerful and easy to overreach. Always preview with dir /S first:
dir /S *.tmp
del /S /P *.tmp
/P with /S walks the tree and confirms file by file — slow, but safe while you learn the pattern.
Attribute filters: /A
/A lets you target files by attributes (hidden, system, read-only, archive, and more). Example — delete only hidden matches:
del /A:H *.tmp
Attribute letters follow the same style as dir /A. Prefer explicit filters over “delete everything and hope.”
Useful workflows
Preview, then delete
dir *.tmp
del /P *.tmp
Clean a known temp pattern quietly
del /Q C:\builds\out\*.obj
Wipe read-only leftovers after a failed build
del /F /Q C:\builds\out\*.pdb
Recursive cleanup with confirmation
del /S /P *.log
DEL vs File Explorer
| Need | Why DEL helps |
|---|---|
| Exact patterns | Wildcards beat hunting files by hand |
| Scripts / automation | Repeatable cleanup in a .bat file |
| Already in a prompt | No context switch to Explorer |
| Safety prompts |
/P confirms each match before it goes |
Common mistakes
Wrong current directory
Relative deletes always resolve from the current directory. If the “wrong” files disappear, check where you are:
cd
dir
Prefer a full path when the stakes are high:
del /P C:\Users\Public\temp\*.tmp
Deleting folders with DEL
del removes files, not directories. Empty folders stay behind. To remove a directory tree, use rmdir / rd (often with /S) after the files are gone — that is a separate command with its own risks.
Broad wildcards + quiet mode
This combination is the classic foot-gun:
del /Q *.*
If you must clear a folder of files, preview with dir first, prefer a narrower pattern, and use /P until the habit sticks.
Assuming Recycle Bin
Files removed with del do not go to the Recycle Bin. Recovery means backups, shadow copies, or undo tools — not Ctrl+Z in Explorer. Treat every delete as permanent.
Quick reference
| Goal | Command |
|---|---|
| Delete one file | del file.tmp |
| Confirm each match | del /P *.tmp |
| Quiet (no prompt) | del /Q *.log |
| Force read-only | del /F locked.txt |
| Include subfolders | del /S *.tmp |
| Safe recursive cleanup | del /S /P *.tmp |
| Same as DEL | erase notes.tmp |
Practice DEL hands-on
Typing the command a few times sticks better than reading about it — especially the safety flags.
CMD Master is a free online interactive learning platform for the command line. Practice Windows CMD, PowerShell, and Bash in a live browser terminal with instant feedback — no install and no VM. Most lessons are free. For a structured Windows path that covers core commands like DEL, start the interactive Windows Command Prompt course.
Tip: run del /? once in a real prompt, then practice del /P on a throwaway *.tmp folder until the confirm loop feels automatic.
Top comments (0)