How to Delete a File in CMD: A Complete Guide to Windows Command Prompt File Deletion
Deleting files through Windows Explorer is straightforward, but the Command Prompt (CMD) gives you a faster, more powerful way to remove files — especially when dealing with batches, hidden files, or stubborn items that won't delete through the normal interface. Whether you're a developer, IT professional, or just a curious user, understanding CMD file deletion opens up a level of control that the graphical interface simply can't match.
What Is the DEL Command?
The primary command for deleting files in CMD is DEL (short for delete). It's a built-in Windows command that removes one or more files directly from the file system. Unlike dragging files to the Recycle Bin, files deleted with DEL are permanently removed — they bypass the Recycle Bin entirely.
This is important to understand before you start. There's no "undo" from the command line the way there is in File Explorer.
Basic Syntax for Deleting a File
DEL [pathfilename] Example:
DEL C:UsersYourNameDocuments eport.txt This deletes the file report.txt from the specified location. If the file is in your current working directory, you can skip the full path:
DEL report.txt To navigate to a specific folder first, use the CD (change directory) command:
CD C:UsersYourNameDocuments DEL report.txt Useful DEL Command Flags and Options 🛠️
CMD file deletion becomes significantly more powerful when you add switches (flags) to the basic command:
| Switch | What It Does |
|---|---|
/F | Forces deletion of read-only files |
/S | Deletes matching files from all subdirectories |
/Q | Quiet mode — skips the confirmation prompt |
/A | Selects files based on attributes (e.g., hidden, read-only) |
/? | Displays help for the DEL command |
Example — Force delete a read-only file:
DEL /F C:UsersYourNameDesktoplocked-file.txt Example — Delete all .log files in a folder and its subfolders:
DEL /S /Q C:Logs*.log The asterisk (*) is a wildcard — it matches any filename with the .log extension. You can also use *.* to match all files in a directory, though this should be used with extreme caution.
How to Delete Files with Spaces in the Name
If a filename or folder path contains spaces, wrap it in quotation marks:
DEL "C:UsersYourNameDocumentsmy old report.txt" Skipping the quotes causes CMD to misread the path and return an error — this is one of the most common beginner mistakes.
Deleting Multiple Files at Once
You can delete several files in a single command using wildcards or listing files separated by spaces:
DEL file1.txt file2.txt file3.txt Or use a wildcard pattern to delete all files of a specific type:
DEL *.txt This removes every .txt file in the current directory. Combined with /S, it will sweep through subdirectories as well — useful for cleanup tasks, but something to double-check before running.
What About Deleting Folders?
The DEL command does not delete folders — it only works on files. To remove an entire directory and its contents, you need the RMDIR command (also written as RD):
RMDIR /S /Q C:UsersYourNameOldFolder /Sremoves the folder and everything inside it/Qsuppresses the "Are you sure?" confirmation
Without /S, RMDIR will only remove an empty directory.
Deleting Stubborn or System Files
Sometimes files refuse to delete because they're in use, protected, or have special attributes. A few approaches:
- Use
/Fto override read-only restrictions - Use
/A:Hto target hidden files:DEL /A:H filename - Run CMD as Administrator — right-click the Command Prompt icon and select Run as administrator — this gives you elevated permissions to remove system-protected files
For files locked by a running process, you may need to close that application first or use Task Manager to end the relevant process before deletion will work.
The Variables That Affect How This Works for You 🔍
The right approach to CMD file deletion depends on several factors specific to your situation:
Your Windows version matters — CMD behavior is consistent across Windows 10 and 11, but older versions like Windows 7 or 8 may handle certain switches slightly differently.
Your permission level determines what you can delete. A standard user account can't remove system files or files owned by other user profiles without administrator elevation.
File attributes play a role — read-only, hidden, and system-flagged files require additional switches or elevated permissions to remove.
Your comfort with the command line affects how you approach wildcard usage. A single misplaced * in the wrong directory can delete far more than intended.
Your purpose shapes the method — cleaning up a dev environment, removing log files on a schedule, or freeing disk space each calls for a slightly different combination of commands and flags.
Understanding the mechanics of DEL, its switches, and the difference between file and folder deletion gives you a solid foundation. But how aggressive or cautious you should be — which flags to use, whether to run as administrator, how broadly to apply wildcards — depends entirely on what you're working with and what risk you're comfortable taking on your specific system.