Skip to content

ERASE command in Windows

The ERASE command in Windows is a powerful tool that allows users to delete files and directories permanently from their system. This command helps free up disk space by removing unwanted data and can also be used to ensure privacy by securely erasing sensitive files. The ERASE command is a quick and efficient way to clean up your computer and remove any unnecessary clutter.

Terminal window
erase [drive:][path]filename
OptionDescription
/POverwrite every sector with 0 (zero)
/FForce deletion of read-only files
ParameterDescription
drive:Specifies the drive to erase files from
pathSpecifies the path of the file to be erased
filenameSpecifies the name of the file to be erased
Terminal window
erase file.txt

Deletes the file named “file.txt” in the current directory.

Terminal window
erase file1.txt file2.docx file3.xlsx

Deletes multiple files (“file1.txt”, “file2.docx”, “file3.xlsx”) in the current directory.

Terminal window
erase *.*

Deletes all files in the current directory.

Terminal window
erase /s /q directory\*.*

Recursively deletes all files in the specified subdirectory and its subdirectories silently.

Terminal window
erase /f filename.txt

Forces deletion of a file named “filename.txt” without asking for confirmation.

Terminal window
erase "\\?\C:\very_long_file_name_1234567890.txt"

Deletes a file with a long filename by using the extended path syntax.

Terminal window
erase /f /a:r readonlyfile.txt

Forces deletion of a read-only file named “readonlyfile.txt” without confirmation.

Terminal window
erase /s /q /f directoryname

Removes an empty directory named “directoryname” and any empty subdirectories silently.

To use the erase command in Windows, execute the following command:

Terminal window
erase C:\example\file.txt

What is the purpose of the erase command in CMD?

Section titled “What is the purpose of the erase command in CMD?”

The erase command in CMD is used to delete files or folders from a specified location on a Windows system.

Terminal window
erase C:\example\folder /s

Is it possible to recover data after using the erase command in Windows?

Section titled “Is it possible to recover data after using the erase command in Windows?”

No, the erase command in Windows permanently deletes files and folders, making data recovery impossible. It is crucial to double-check before executing the command.

Terminal window
erase D:\important\file.docx

How can I delete multiple files using the erase command in CMD?

Section titled “How can I delete multiple files using the erase command in CMD?”

You can delete multiple files using the erase command in CMD by specifying the files separated by spaces.

Terminal window
erase C:\example\file1.txt C:\example\file2.txt

Can the erase command in Windows be used to delete system files?

Section titled “Can the erase command in Windows be used to delete system files?”

Yes, the erase command in Windows can be used to delete system files, but it requires administrative privileges to do so.

Terminal window
erase C:\Windows\System32\file.dll

What happens if I use the erase command on a read-only file or folder?

Section titled “What happens if I use the erase command on a read-only file or folder?”

If you attempt to use the erase command on a read-only file or folder, you will receive an error message indicating that the operation is not permitted.

Terminal window
erase E:\example\read-only-file.txt

How can I permanently delete a directory with all its contents using the erase command?

Section titled “How can I permanently delete a directory with all its contents using the erase command?”

To permanently delete a directory with all its contents, you can use the /s flag with the erase command in CMD.

Terminal window
erase D:\example\folder /s

Is it possible to use wildcards with the erase command in Windows?

Section titled “Is it possible to use wildcards with the erase command in Windows?”

Yes, you can use wildcards with the erase command in Windows to delete multiple files based on a pattern matching criteria.

Terminal window
erase C:\example\*.txt

How can I list the files in a directory before using the erase command to avoid accidental deletions?

Section titled “How can I list the files in a directory before using the erase command to avoid accidental deletions?”

Before using the erase command, you can list the files in a directory by using the dir command to ensure you are deleting the correct files.

Terminal window
dir C:\example
  • To delete one or more files.
  • To delete directories and all their contents.
  • To free up disk space by removing unwanted or temporary files.
  • To clean up the system and improve performance.
  • To remove sensitive or confidential information before selling or disposing of a computer.