Javascript required
Skip to content Skip to sidebar Skip to footer

How to Remove a File in Windows Command Line

With simple commands, you can delete any file you want from the Command Prompt. Follow the below steps to learn how.

Using command prompt and PowerShell, you can do almost anything on Windows 10. Deleting a file or a bunch of files is nothing hard. Though you can easily delete files by pressing the Delete key on your keyboard, there might be times when you need to use the commands to delete files.

So, in this short tutorial let me show you the simple commands to delete files in Windows.

Command to Delete Files

When you want to delete something via the Command Prompt, there are multiple scenarios. For instance, you can delete a single file, delete multiple files, delete files with a specific extension, delete read-only files, etc.

To make things easier, I've divided the commands into their own sections. Depending on what you are looking for, click on the jump link below to see the command usage.

Jump to delete:

  • Single file
  • Multiple files
  • Files with a specific extension
  • Read-only files

Files deleted via below commands are not moved to the Recycle Bin. i.e, they are deleted permanently. Which simply means that you cannot recover them. So, be careful about what you are deleting.

The del commands shown below will also work with PowerShell.

1. Command to delete a single file

To delete a single file, all you need to do is execute a single command with the file name.

1. First, search for cmd in the start menu, right-click on Command Prompt and select Run as administrator option to open an elevated command prompt.

Note: You can delete files without admin privileges as long as the files belong to your user account.

2. Now, use the cd command to go to the folder where the files you want to delete are located. For instance, the files I want to delete are in a folder named "del" on my desktop. So, I use the following command.

cd c:\users\vamsi\desktop\del
Command to delete file 01

Once you are in the folder, simply execute the below command to delete a file. Don't forget to replace <filename> with the actual file name along with its file extension. In my case, the file name is image-1.jpg.

del <filename>
Command to delete file 02

When you successfully delete a file, you will not see any confirmation message. However, if there is any problem, the command prompt will show an error message.

2. Delete multiple files with a command

There are two ways to delete multiple files in the command prompt. In the first method, you will specify all the file names manually. This gives you better control over the files you delete. The second method is to use the wildcard. This is useful for bulk delete operations.

2.1 Specify file names manually

When you have multiple specific files to delete, you can manually specify the file names. The advantage of this method is that you will only delete those files and ignore all others.

1. Just like before, open the Command Prompt and go to the folder where the files to delete are located.

2. Next, execute the below command while replacing <filname1>, <filename2>, etc., with the actual filenames. You can specify as many filenames as you want.

del <filename1> <filename2>
Command to delete file 03

2.2 Bulk delete files with a wildcard

To bulk delete files in a folder, you can use * ( wildcard ). The wildcard feature is very useful when you want to delete all files, files with a specific name, files with a specific extension, etc., in a folder.

1. To delete all files in a folder, use the below command.

2. Since you are deleting all the files in a folder, Windows will warn you. Simply type Y and press Enter to confirm file deletion.

del *
Command to delete file 04

3. Delete all files that start with a specific name. The below command will delete all the files with the name that starts with "image".

del image*
Command to delete file 06

3. Delete all files that contain a specific word. The below command will delete all the files with the name that contains "tFile".

del *tFile*
Command to delete file 05

3. Command to delete files with a specific extension

1. If you are looking to delete files that have a specific file extension then you can use the below command. Don't forget to replace "fileExtension" with the actual file extension, like png, jpg, zip, etc.

del *.fileExtension

For example, to delete all the PNG files in a folder, the command with look something like this.

del *.png
Command to delete file 07

2. To delete all files with a specific name and file extension, use the below command. Don't forget to replace the file name and extension to match your needs.

del ima*.png
Command to delete file 08

4. Delete read-only file with Command Prompt

Read-only files are protected and are generally difficult to delete, by design. If you try to delete a read-only file via command prompt using the above command, you will receive "Access is denied" error message.

To delete a read-only via the command prompt, you need to force it.

Command to delete file 09

1. Open the command prompt and navigate to where the file is located.

2. Once you are here, use the below command. Replace <filename> with the actual filename.

del /f <filename>
Command to delete file 10

3. As an alternative, you can also use this command to delete read-only files.

del /a:r <filename>

Wrapping Up

As you can see, commands to delete files in Windows are pretty simple and straight forward. All you need is a single command and you are good to go.

If you are stuck or need some help, comment below and I will try to help as much as possible.

If you like this article, you might also like to know how to force delete locked files in Windows 10 and how to delete a single URL from chrome and firefox auto-complete history. Do check them out.

How to Remove a File in Windows Command Line

Source: https://windowsloop.com/commands-to-delete-files-on-windows/