del

删除一个或多个文件。 This command performs the same actions as the erase command.

The del command can also run from the Windows Recovery Console, using different parameters. 有关详细信息,请参阅 Windows 恢复环境 (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> 指定一个或多个文件或目录的列表。 通配符可用于删除多个文件。 如果指定了目录,则将删除该目录中的所有文件。
/p 删除指定文件前提示用户进行确认。
/f 强制删除只读文件。
/s 从当前目录和所有子目录中删除指定的文件。 显示正在删除的文件的名称。
/q 指定安静模式。 系统不会提示你确认删除。
/a[:]<attributes> 根据以下文件属性删除文件:
  • r Read-only files
  • h Hidden files
  • i Not content indexed files
  • s System files
  • a Files ready for archiving
  • l Reparse points
  • - 用作前缀,表示“非”
.
/? 在命令提示符下显示帮助。

Remarks

  • 如果使用 del /p 命令,你将看到以下消息:

    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.

  • 如果在 <names> 参数中指定特定文件夹,则所有包含的文件也将被删除。 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. 但是,为避免无意中删除文件,应谨慎使用通配符。 例如,如果键入以下命令:

    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

要删除驱动器 C 上名为 test 的文件夹中的所有文件,请键入以下任一命令:

del c:\test
del c:\test\*.*

若要删除文件夹中名称中包含空格的所有文件,需要用双引号将完整路径括起来。 键入以下任一命令:

del "c:\test folder\"
del "c:\test folder\*.*"

要从当前目录中删除文件扩展名为 .bat 的所有文件,请键入:

del *.bat

要删除当前目录中的所有只读文件,请键入:

del /a:r *.*