ERASE: Deletes one or more files.
The command: "ERASE" is on Windows 11, 10, .. available
The examples for the command "ERASE"
command in Windows Command Prompt is used to delete files. Here are some examples:
Example 1: Delete a single file:
Deletes the file named "Example.txt"
in the current directory.
Example 2: Delete multiple files:
ERASE file1.txt file2.txt file3.txt
Deletes the specified files in the current directory.
Example 3: Delete all files with a specific extension:
Deletes all files with the extension ".log"
in the current directory.
Example 4: Delete files in another directory:
Deletes all files with the extension ".txt"
in the specified directory.
Example 5: Delete all files in the current directory:
Deletes all files in the current directory.
Example 6: Delete with confirmation prompt:
ERASE /P *.tmp
Requests confirmation before deleting each file. The user is prompted to answer "yes"
Example 7: Deleting files in a directory and its subdirectories:
ERASE /S "C:\Path\to\Files\*.bak"
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"
Deletes all hidden files with a ".doc"
extension in the specified directory and all subdirectories, asking for confirmation before each deletion.
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.
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:
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., `*`
) 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`
ERASE /F Read-onlyFile.txt
6. Deleting read-only and hidden files (/A:H, /A:S):
(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):
option allows deleting files in subdirectories.
ERASE /S "C:\Path\to\Files\*.tmp"
8. Skip read-only files (/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.
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.