The CMD del command is used to delete files from the command line in the Windows operating system.
del file-nameWe can delete multiple files at once:
del file1.txt file2.txtNotes
- The del command removes files permanently without sending them to the Recycle Bin.
- If you use the /p option, the del command prompts for confirmation before deleting each file.
- There is another command, the erase command, and it is identical to the del command, and the syntax is similar.
- To force delete read-only files, use the /F option.
- We can use the wildcard (*) character to remove all files in a directory.
- To delete folders, use the rmdir command.
DEL Command Examples
Remove the file file1.txt in the current directory:
del file1.txtRemove the file file1.txt in the c:\data directory:
del C:\data\file1.txtThe following command uses the /F option to force delete file1.txt if it is a read-only file:
del /f file1.txtRemove all files in the c:\data directory:
del /q *Remove all text files (files with .txt extension) in the current directory:
del *.txtDelete all files with the pattern file.* (e.g., file1.txt, file2.txt, file1.doc, etc.) in the c:\data directory:
del file*When using the wildcard character, the del command prompts for confirmation by default. You can use the \Q option to suppress the confirmation message.
In the following example, The windows del command deletes all files from c:\data and all subdirectories. The /S option is used to remove the specified file(s) from all subdirectories.
del /s /q C:\data\*However, the del command does not remove subdirectories, only files inside subdirectories.
The del command does not delete hidden files by default. To include hidden files, use the /a:h switch:
del /a:h file1.txtThe following command deletes all hidden files in the current directory:
del /a:h *The /a switch is used to delete files based on their attributes (H represents hidden files). To see a list of all options, type del /?.
I can't for the life of me remember how to bypass the annoying prompt are you sure? Y/N when deleting files.
I seem to recall it was something like:
del C:\Test && ECHO Y
Jij
1051 gold badge1 silver badge12 bronze badges
asked Aug 23, 2011 at 11:32
Michael SkeltonMichael Skelton
1,9853 gold badges14 silver badges7 bronze badges
1
Use del /F /Q to force deletion of read-only files (/F) and directories and not ask to confirm (/Q) when deleting via wildcard.
answered Aug 23, 2011 at 11:34
Kerrek SBKerrek SB
455k89 gold badges864 silver badges1065 bronze badges
0
Add /Q for quiet mode and it should remove the prompt.
Uwe Keim
38.9k56 gold badges174 silver badges286 bronze badges
answered Aug 23, 2011 at 11:35
Nicholas SmithNicholas Smith
11.6k6 gold badges35 silver badges54 bronze badges
I just want to add that this nearly identical post provides the very useful alternative of using an echo pipe if no force or quiet switch is available. For instance, I think it's the only way to bypass the Y/N prompt in this example.
Echo y|NETDOM COMPUTERNAME WorkComp /Add:Work-CompIn a general sense you should first look at your command switches for /f, /q, or some variant thereof (for example, Netdom RenameComputer uses /Force, not /f). If there is no switch available, then use an echo pipe.
Uwe Keim
38.9k56 gold badges174 silver badges286 bronze badges
answered Aug 11, 2015 at 19:47
1
If you are using powershell, for example from vscode terminal, you can use -Recurse -Force instead:
del C:\Test -Recurse -ForceNote: I know that the question have cmd tag, but someone might come here for powershell or vscode.
answered Jan 25 at 6:32
You have the following options on Windows command line:
net use [DeviceName [/home[{Password | *}] [/delete:{yes | no}]]Try like:
net use H: /delete /y
Pang
9,275146 gold badges85 silver badges120 bronze badges
answered Sep 14, 2017 at 3:56
slonslon
9961 gold badge7 silver badges12 bronze badges
1