DEL or ERASE

(DEL from Delete)

Deletes one or more files.

DEL [/P | /Q] [/F] [/S] [/A[[:][-]attr1 [[-]attr2 [...]]]] filename
ERASE [/P | /Q] [/F] [/S] [/A[[:][-]attr1 [[-]attr2 [...]]]] filename

Where:

  • filename - Specifies one or more files or directories. If a directory is specified, the files in it are deleted.
  • /P - Asks for confirmation before deleting each file.
  • /Q - Silent mode, does not ask for confirmation for global deletions.
  • /F - Force deletes read-only files.
  • /S - Deletes files from all subdirectories and shows deleted file names.
  • /A[[:][-]attr1 [[-]attr2 [...]]] - Chooses files to delete based on attributes (see ATTRIBATTRIB and DIRDIR). The - sign in front of the specified attribute preserves files with that attribute. Replace attr1, attr2, etc… with:
    • R - Read-only files.
    • A - Archive files.
    • S - System files.
    • H - Hidden files.
    • I - Not indexed files.
    • T - Temporary files.
    • O - Offline files.
    • L - Symbolic links.
    • C - Compressed files.
    • E - Encrypted files.
    • X - Clean files.
    • V - On ReFS volumes (introduced in Windows 8): Healthy files; on FAT volumes: Deprecated.
    • P - Since Windows 10 v1703: pinned files (always available on OneDrive); before Windows 10 v1703: sparse files (disk allocation only for non-null data).
    • U - Unpinned files (online only on OneDrive, introduced in Windows 10 v1703).
    • M - Strictly sequential files (introduced in Windows 10 v1703).
    • B - Recall on data access files (introduced in Windows 10).
  • If attributes are specified without -, only files with those attributes are deleted. If attributes are preceded by -, all files except those with the specified attributes are deleted. You can use * in the file name or extension to select files with the same name or extension.

    Examples:

    1. Delete the file C:\WINDOWS\system32\command.com asking for confirmation:

    del /p "C:\WINDOWS\system32\command.com"

    or:

    erase /p "C:\WINDOWS\system32\command.com"

     

    2. Delete files in the C:\z directory except those with the archive attribute in silent mode:

    del /q /a:-a "C:\z"

    or:

    erase /q /a:-a "C:\z"

Comments