Windows Del Command, Delete Files Using CMD
The CMD del
command is used to delete files from the command line in the Windows operating system.
del file-name
We can delete multiple files at once:
del file1.txt file2.txt
Notes
- The
del
command removes files permanently without sending them to the Recycle Bin. - If you use the
/p
option, thedel
command prompts for confirmation before deleting each file. - There is another command, the
erase
command, and it is identical to thedel
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.txt
Remove the file file1.txt
in the c:\data
directory:
del C:\data\file1.txt
The following command uses the /F
option to force delete file1.txt
if it is a read-only file:
del /f file1.txt
Remove all files in the c:\data
directory:
del /q *
Remove all text files (files with .txt
extension) in the current directory:
del *.txt
Delete 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.txt
The 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 /?
.