≡ Menu

Delete any kind of file from command line

Learn how to use del command for deleting files from command prompt/CMD. This command works for read-only files and supports wildcards too.

Run del command with the name of the file to be deleted, you are done!

del filename

You do not see message after running the command if the file is deleted successfully. Error message is shown only when something goes wrong.

Delete Read only files

We can’t delete a read-only file using simple‘del’ command. We get access denied error in this scenario.

c:\>attrib readonlyfile.txt
A    R       C:\readonlyfile.txt
c:\>del readonlyfile.txt
c:\readonlyfile.txt Access is denied.

Run del /F to delete a read only file.

del /F readonlyfile.txt

Alternatively, you can use del /A too

del /A:R readonlyfile.txt

Delete files in bulk

Del command recognizes wildcard(*) and so can be used to delete files in bulk from CMD.  Some examples below.
To delete all the files in current folder

del *

To delete all the files with ‘log’ extension

del *.log

Delete all files having the prefix ‘abc’

del abc*

Delete all files having ‘PIC’ somewhere in the file name.

del *PIC*

The above are the basic use cases of del command. Continue to read below for non trivial use cases.

Add multiple file name in the command

‘Del’ command can accept multiple files as argument

del filename1 filename2 filename3 filename4....


D:\>dir /s /b
1.pdf 2.pdf 3.pdf
D:\>del 1.pdf 2.pdf 3.pdf
D:\>dir /s /b

Related posts:
How to delete empty files from CMD

4 comments… add one
  • Garg

    Is there any batch command to delete all empty files from cmd.

    • Srini

      Added link in the post.

  • ClayStation

    There is a way to remove folders from the commandline, use “RD” (remove directory), and it has a couple of silent switches, “RD /S /Q C:/Directory” will remove C:/Directory silently, I use this all the time. I think that the directory path has to be in quotations if it contains any spaces.

  • ClayStation

    UAC might want to fight over deleting files, in that case, the command “takeown” to give you ownership of the file first, should get around that.

Leave a Comment