ShareYourGroupShareYourGroupCommands

Windows commands

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

Windows Command Prompt
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.txt

No 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.

Windows Command Prompt
C:\Users\asha\demo>del nothing.txt
Could Not Find C:\Users\asha\demo\nothing.txt

Deleting by pattern

Wildcards delete every matching file. First look, then delete.

Windows Command Prompt
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
photos

The 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:

Windows Command Prompt not run here
del photos

Windows 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

SwitchEffect
/pask before deleting each file
/qquiet: never ask, even for *.*
/salso delete matching files in all subfolders
/fforce deletion of read-only files
/achoose 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

  1. Run cd, with nothing after it, and read where you are.
  2. Run dir with exactly the pattern you intend to delete.
  3. Read the list. Is anything there that you want to keep?
  4. Only then run del with the same pattern. Press the up arrow to bring back the dir line and change the word, so that the pattern is identical.
  5. For anything important, move the files to a holding folder with move instead 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

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.