The command: "ERASE" is on Windows 12, 11, 10, .. , MS Server 2025, 2022, 2019, .. available
The examples for the command "ERASE"
The
`ERASE` command in Windows Command Prompt is used to delete files. Here are some examples:
Example 1: Delete a single file:
ERASE example.txt
Description: Deletes the file named
"Example.txt" in the current directory.
Example 2: Delete multiple files:
ERASE file1.txt file2.txt file3.txt
Description: Deletes the specified files in the current directory.
Example 3: Delete all files with a specific extension:
ERASE *.log
Description: Deletes all files with the extension
".log" in the current directory.
Example 4: Delete files in another directory:
ERASE "C:\Path\to\Files\*.txt"
Description: Deletes all files with the extension
".txt" in the specified directory.
Example 5: Delete all files in the current directory:
ERASE *.*
Description: Deletes all files in the current directory.
Example 6: Delete with confirmation prompt:
ERASE /P *.tmp
Description: Requests confirmation before deleting each file. The user is prompted to answer
"yes" or
"no".
Example 7: Deleting files in a directory and its subdirectories:
ERASE /S "C:\Path\to\Files\*.bak"
Description: Deletes all files with the extension
".bak" in the specified directory and all subdirectories.
Example 8: Graceful Wipe with Restore Option:
ERASE /P /S /A:H "C:\Path\to\Files\*.doc"
Description: Deletes all hidden files with a
".doc" extension in the specified directory and all subdirectories, asking for confirmation before each deletion.
Note: Note that the
`ERASE` command permanently deletes files. It is important to be careful and ensure that you delete the correct files, as deleted files usually cannot be easily recovered. Use this command carefully.
"ERASE" Excerpt from Microsoft Windows Help
Microsoft Windows [Version 10.0.19045.3693]
(c) Copyright 1985-2023 Microsoft Corp.
C:\\WINDOWS>
Deletes one or more files.
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
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 each file.
/F Force deleting of read-only files.
/S Delete specified files from all subdirectories.
/Q Quiet mode, do not ask if ok to delete on global wildcard
/A Selects files to delete based on attributes
attributes R Read-only files S System files
H Hidden files A Files ready for archiving
- Prefix meaning not
If Command Extensions are enabled DEL and ERASE change as follows:
The display semantics of the /S switch are reversed in that it shows
you only the files that are deleted, not the ones it could not find.
Important information, tips for the "ERASE" command
There are a few important points to note when using the
`ERASE` command in the Windows Command Prompt:
1.
Irrecoverable Deletion: The
`ERASE` command deletes files irrevocably. Deleted files usually cannot be easily recovered. Make sure you delete the correct files and be careful, especially when using the command in scripts or batch files.
2.
Wildcard Usage: When using wildcards (e.g.,
`*` or
`?`) with
`ERASE`, be particularly careful. More files could be deleted than intended. A confirmation prompt (
`/P`) can help prevent accidental deletion.
3.
Paths with spaces: If the paths or filenames contain spaces, you should enclose them in quotation marks to ensure they are interpreted correctly.
ERASE "C:\Path with spaces\Example file.txt"
4.
Delete with Confirmation (/P): Using the
`/P` (Prompt) option requires confirmation before deleting each file. This can help prevent accidental deletions.
ERASE /P file.txt
5.
Deleting read-only files (/F): If you want to delete read-only files, use the
`/F` option.
ERASE /F Read-onlyFile.txt
6.
Deleting read-only and hidden files (/A:H, /A:S): The
`/A:H` (Hidden) and
`/A:S` (System) options allow deleting hidden ones and system protected files.
ERASE /A:H /A:S HiddenAndSystemFile.txt
7.
Deleting files in subdirectories (/S): The
`/S` option allows deleting files in subdirectories.
ERASE /S "C:\Path\to\Files\*.tmp"
8.
Skip read-only files (/I): The
`/I` option can be used to skip read-only files without asking for confirmation.
ERASE /I Read-onlyFile.txt
9.
Deleting files with specific extensions: If you only want to delete files with a specific extension, you can use wildcards.
ERASE *.log
It is important to note that the
`ERASE` command does not use the Recycle Bin and the deleted files usually cannot be recovered. Therefore, you should make sure that you only delete files when you are sure that it is necessary.