del: delete files
del deletes files. It is simple to use, and that is the problem: files deleted from the Command Prompt do not go to the Recycle Bin. They are gone at once. This page is as much about deleting safely as about the command.
Danger. There is no undo for del. Before deleting with a wildcard, list the same files with dir. Before deleting in a folder, check the prompt to see which folder you are in.
Deleting one file
C:\Users\asha\demo>dir /b
log.txt
marks.csv
notes.txt
old
photos
report.txt
C:\Users\asha\demo>del notes.txt
C:\Users\asha\demo>dir /b
log.txt
marks.csv
old
photos
report.txtNo message means it worked. erase is another name for the same command.
If the file is not there, del says so and does nothing else.
C:\Users\asha\demo>del nothing.txt
Could Not Find C:\Users\asha\demo\nothing.txtDeleting by pattern
Wildcards delete every matching file. First look, then delete.
C:\Users\asha\demo>dir /b *.txt
log.txt
report.txt
C:\Users\asha\demo>del *.txt
C:\Users\asha\demo>dir /b
marks.csv
old
photosThe dir line is the safety step. Whatever it lists is what del will remove.
Deleting everything in a folder
Giving a folder name deletes all the files directly inside it. The folder itself and any subfolders stay. Because this is drastic, del asks first. Here the command is shown without being run:
del photosWindows replies C:\Users\asha\demo\photos\*, Are you sure (Y/N)? and waits. Typing N cancels. del *.* and del * ask the same question.
The switches
| Switch | Effect |
|---|---|
/p | ask before deleting each file |
/q | quiet: never ask, even for *.* |
/s | also delete matching files in all subfolders |
/f | force deletion of read-only files |
/a | choose files by attribute, such as /ah for hidden |
/p is the careful one. It names each file and waits for Y or N.
Danger. del /s /q *.* deletes every file in the current folder and in every folder below it, without asking. Run in the wrong place, such as the top of a drive or your user folder, it destroys years of work in seconds. Never type it from memory, never paste it from a website, and never run it without first running cd to see where you are.
A safe routine
- Run
cd, with nothing after it, and read where you are. - Run
dirwith exactly the pattern you intend to delete. - Read the list. Is anything there that you want to keep?
- Only then run
delwith the same pattern. Press the up arrow to bring back thedirline and change the word, so that the pattern is identical. - For anything important, move the files to a holding folder with
moveinstead of deleting. Delete the holding folder a week later.
Folders
del removes files, never folders. To remove a folder, use rmdir, described on the page about cd, mkdir and rmdir.
When del refuses
- "Access is denied." The file is read-only (use
/f), is open in a program, or you do not have permission. Close the program that has it open. - "The process cannot access the file because it is being used by another process." Something still has it open.
- "Could Not Find" means the name or pattern matched nothing. Check the spelling and the folder.
Can deleted files be recovered?
Sometimes. Deleting removes the file's entry from the folder, and the data stays on the disk until something else is written over it. Recovery programs can occasionally find it, more often on older hard disks than on modern solid-state drives. The chances fall quickly as the computer is used. Do not rely on it. A backup is the only dependable recovery.
File History and OneDrive, if switched on, keep earlier copies of files in the folders they cover.
Deleting from File Explorer instead
If you are not sure, delete with File Explorer. Files go to the Recycle Bin and can be restored. Opening the current folder from the Command Prompt takes one command: start .
On Linux and the Mac, the matching command is rm, which is just as final.
Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.
This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.