How to Delete a File from the Command Prompt

Delete a File from the Command Prompt: Deleting a file is extremely easy on Windows or another operating system. In Windows, all you have to do is right-click the file and then click the Delete option. You can also delete a file by selecting it before pressing the delete key.

How to Delete a File from the Command Prompt
How to Delete a File from the Command Prompt

Sometimes, however, you may come across a file that cannot be deleted with a click of the mouse. Of course, there are a number of free applications that allow you to delete a file that cannot be deleted by selecting it or right-clicking on it.

How to Delete a File from the Command Prompt

In most cases, however, files cannot be deleted from Windows Explorer from the command prompt without installing third-party applications. And if you’ve never used Command Prompt before, it’s not as difficult as it sounds.

Follow the instructions below to delete a file from the command line in all versions of Windows.

WARNING: If you delete a file from the command line, the file is not moved to the Recycle Bin. This means that the file is permanently deleted and cannot be restored from the recycle bin. Therefore, make sure that you no longer need or save the file before deleting it.

Use the command prompt to delete a file

Step 1: To delete a file from the command prompt, we recommend that you open the elevated command prompt. To do this, start the command prompt as administrator by typing CMD in the start menu or in the dialog box start screen and then simultaneously pressing the keys Ctrl + Shift + Enter.

If you’re not the administrator and can’t open the elevated command prompt, you can also try deleting the file by opening the normal command prompt.

Step 2: To delete a specific file, you first need to know the path to the file. That means you need to know exactly where the file is located. To find the path to the file, hold down the Shift key before right-clicking the file, and then click the Copy as Path option to copy the path.

Step 3: Then run the following command to delete the file:

Delete path to the file

Example: Delete "E: \ Test \ Machine \ Rain.txt".

The command prompt in Windows 7/8 / 8.1 does not allow you to paste with the command Ctrl + V. You have to right-click and then click on the Paste option. However, in Windows 10, you can paste the path by pressing Ctrl + V.

And if you get the “Can’t find” error message, it’s probably because you either didn’t specify the file extension or entered an incorrect path. That means you have to enter the file extension along with the path and name to delete it.

That’s it!

To get a confirmation prompt before deleting a file, run the command as follows:

Del / P path to the file

Example: Del / P “E: \ Office.docx”

And if you get denied access, it’s probably because of its read-only attribute.

To force a read-only file to be deleted:

Del / F path to the file

Example: Del / F "E: \ Office.docx"

How to delete all files in a folder

Del / A path to the folder

Note that the folder and subfolders are not deleted.

Leave a Comment

Your email address will not be published. Required fields are marked *