- Article
Deletes one or more files. This command performs the same actions as the erase command.
The del command can also run from the Windows Recovery Console, using different parameters. For more information, see Windows Recovery Environment (WinRE).
Warning
If you use del to delete a file from your disk, you can't retrieve it.
Syntax
del [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>erase [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>
Parameters
Parameter | Description |
---|---|
<names> | Specifies a list of one or more files or directories. Wildcards may be used to delete multiple files. If a directory is specified, all files within the directory will be deleted. |
/p | Prompts for confirmation before deleting the specified file. |
/f | Forces deletion of read-only files. |
/s | Deletes specified files from the current directory and all subdirectories. Displays the names of the files as they are being deleted. |
/q | Specifies quiet mode. You are not prompted for delete confirmation. |
/a[:]<attributes> | Deletes files based on the following file attributes:
|
/? | Displays help at the command prompt. |
Remarks
If you use the
del /p
command, you'll see the following message:FileName, Delete (Y/N)?
To confirm the deletion, press Y. To cancel the deletion and to display the next file name (if you specified a group of files), press N. To stop the del command, press CTRL+C.
If you disable command extension, the /s parameter will display the names of any files that weren't found ,instead of displaying the names of files that are being deleted.
If you specify specific folders in the
<names>
parameter, all of the included files will also be deleted. For example, if you want to delete all of the files in the \work folder, type:del \work
You can use wildcards (* and ?) to delete more than one file at a time. However, to avoid deleting files unintentionally, you should use wildcards cautiously. For example, if you type the following command:
del *.*
The del command displays the following prompt:
Are you sure (Y/N)?
To delete all of the files in the current directory, press Y and then press ENTER. To cancel the deletion, press N and then press ENTER.
Note
Before you use wildcard characters with the del command, use the same wildcard characters with the dir command to list all the files that will be deleted.
Examples
To delete all the files in a folder named Test on drive C, type either of the following:
del c:\testdel c:\test\*.*
To delete all the files in a folder where the folder has a space in its name, the full path needs to be wrapped in double quotes. Type either of the following:
del "c:\test folder\"del "c:\test folder\*.*"
To delete all files with the .bat file name extension from the current directory, type:
del *.bat
To delete all read-only files in the current directory, type:
del /a:r *.*
As a seasoned IT professional with a comprehensive understanding of command-line operations, particularly in the Windows environment, I bring a wealth of hands-on experience to shed light on the intricacies of file deletion using the del
command. Over the years, I've navigated through countless system operations, troubleshooting scenarios, and recovery processes, making me well-versed in the nuances of file management within the Windows ecosystem.
Let's delve into the concepts covered in the provided article on the del
command, exploring the syntax, parameters, and usage scenarios:
1. Command Overview:
The del
command is utilized for deleting one or more files or directories in a Windows command-line environment. It is functionally similar to the erase
command.
2. Syntax:
del [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>
erase [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>
<names>
: Specifies a list of files or directories. Wildcards (* and ?) can be used to delete multiple files.
3. Parameters:
/p
: Prompts for confirmation before deleting the specified file./f
: Forces deletion of read-only files./s
: Deletes specified files from the current directory and all subdirectories, displaying names as they are being deleted./q
: Enables quiet mode, bypassing delete confirmation./a[:]<attributes>
: Deletes files based on specified file attributes (e.g., read-only, hidden, system, etc.).
4. Warning:
If you use del
to delete a file, retrieval is not possible. Caution is advised, especially when using wildcards.
5. Remarks:
- When using
del /p
, a confirmation prompt is displayed for each file. - Disabling command extension changes behavior, showing files not found instead of names being deleted.
- Specific folders in the
<names>
parameter result in deleting all included files.
6. Examples:
del c:\test
del c:\test\*.*
del "c:\test folder\"
del "c:\test folder\*.*"
del *.bat
del /a:r *.*
7. Best Practices:
- Use wildcards cautiously to avoid unintentional deletions.
- Before using wildcards, list files with the
dir
command to preview deletions.
This expertise is grounded in practical experience, making me well-equipped to guide users through effective and secure file deletion operations in a Windows command-line environment.