Config Server Firewall

Windows Del Command, Delete Files Using CMD

windows del command delete file 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

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.

delete all files in a directory cmd
delete all files in a directory

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 /?.