delDEL Command – Delete Files in Windows Command Prompt
Master the DEL command to delete files in Windows CMD. Complete guide with syntax, parameters, wildcards, examples, and best practices for safe file deletion.
The DEL command (Delete) is a Windows Command Prompt utility that permanently removes one or more files from the file system without sending them to the Recycle Bin. Use DEL to delete single files, multiple files with wildcards, or files with specific attributes; the command has an alias ERASE that functions identically—both provide immediate, irreversible file deletion.
Whether you're a system administrator cleaning up log files, a developer removing build artifacts, or a power user managing disk space, DEL provides fast, scriptable file deletion with attribute filtering and confirmation options. IT professionals rely on DEL for automated cleanup tasks, temporary file removal, and batch file deletion across enterprise environments—but its permanent deletion requires careful use.
This comprehensive guide covers DEL syntax, all parameters and attribute filters, practical examples for safe file deletion, troubleshooting tips for deletion failures, related file management commands, and frequently asked questions. By the end, you'll confidently delete files from the command line while avoiding accidental data loss through proper verification and safety practices.
What Is the DEL Command?
The DEL command is a file management tool in Windows Command Prompt that permanently deletes files from the file system. Unlike moving files to the Recycle Bin through Windows Explorer, DEL removes files immediately without recovery options through standard Windows interfaces—deleted files bypass the Recycle Bin entirely.
DEL supports wildcards (* and ?) for batch deletion of multiple files matching patterns, can target files by attributes (hidden, read-only, system, archive), and offers options for confirmation prompts and recursive deletion across subdirectories. DEL works in Command Prompt (CMD), Windows PowerShell (with CMD compatibility), and is available in all Windows versions from MS-DOS through Windows 11, Windows Server 2022, and all enterprise editions.
The command's power and permanence make it essential for system administration, disk cleanup, and automated file management—but also require careful use to prevent accidental data loss. Always verify file selections before deletion, especially when using wildcards or recursive options.
DEL vs ERASE vs RMDIR
- DEL / ERASE: Deletes files only; identical commands with different names
- RMDIR / RD: Removes directories (folders); use
/Sto delete directory contents - Windows Explorer Delete: Moves files to Recycle Bin; allows recovery
Use DEL for permanent file deletion, RMDIR for directories, and Explorer's delete for recoverable deletion.
Syntax
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
Parameters
| Parameter | Description |
|---|---|
/P | Prompts for confirmation before deleting each file |
/F | Forces deletion of read-only files |
/S | Deletes specified files from all subdirectories recursively |
/Q | Quiet mode; does not prompt for confirmation with wildcards |
/A | Deletes files based on specified attributes |
names | Specifies file(s) to delete (wildcards * and ? supported) |
Attribute Filters (/A)
| Attribute | Description |
|---|---|
R | Read-only files |
H | Hidden files |
S | System files |
A | Files ready for archiving (archive attribute set) |
- | Prefix meaning "not" (e.g., -R = not read-only) |
Combining attributes: Use multiple attributes together: /A:RH deletes read-only AND hidden files. Use - to exclude: /A:-R deletes all files except read-only.
Default behavior: Without /A, DEL deletes all files matching the name pattern, excluding read-only files (unless /F is used).
How to Use DEL Command
Delete a Single File
Remove a specific file from the current directory:
DEL file.txt
The file is permanently deleted without confirmation (unless it's read-only).
Delete a File with Full Path
Specify the complete path to delete a file from any location:
DEL C:\Temp\oldfile.txt
Use absolute paths in scripts to avoid ambiguity about which file to delete.
Delete Multiple Files with Wildcards
Use wildcards to delete all files matching a pattern:
DEL *.tmp
DEL backup*.log
DEL data?.csv
*.tmpdeletes all files with .tmp extensionbackup*.logdeletes files starting with "backup" and ending with .logdata?.csvdeletes files like data1.csv, data2.csv (? matches single character)
Delete All Files in a Directory
Use *.* to delete all files in the current directory:
DEL *.*
Windows prompts "Are you sure (Y/N)?" before deleting all files. This is a safety feature for the *.* wildcard.
Delete Without Confirmation (/Q)
Use /Q to suppress confirmation prompts when using wildcards:
DEL /Q *.tmp
DEL /Q /S *.log
Essential for automated scripts and batch files where manual confirmation isn't possible.
Force Delete Read-Only Files (/F)
Use /F to delete files with the read-only attribute:
DEL /F readonly.txt
DEL /F /Q *.bak
Without /F, DEL skips read-only files with "Access is denied" errors.
Delete Files Recursively (/S)
Use /S to delete files in the current directory and all subdirectories:
DEL /S *.log
DEL /S /Q *.tmp
This searches the entire directory tree for matching files and deletes them all.
Warning: /S with wildcards can delete many files across multiple directories. Always verify with DIR /S pattern before using DEL /S pattern.
Delete with Confirmation (/P)
Use /P to prompt before deleting each file:
DEL /P *.txt
Windows displays "Delete [filename]? (Y/N)" for each file, allowing selective deletion.
Delete Hidden Files
Use /A:H to delete only hidden files:
DEL /A:H *.tmp
Without /A:H, DEL skips hidden files by default.
Delete All Files Except Read-Only
Use /A:-R to delete all files except those with read-only attribute:
DEL /A:-R *.*
The -R excludes read-only files from deletion.
Delete Files by Multiple Attributes
Combine attributes to target specific file types:
DEL /A:HS *.sys
This deletes system files that are also hidden.
Preview Files Before Deletion
Use DIR with the same pattern to preview files before deleting:
DIR *.tmp
DEL /Q *.tmp
This two-step approach prevents accidental deletion of wrong files.
Common Use Cases
-
Delete temporary files – Use
DEL *.tmporDEL /S /Q %TEMP%\*.*to clean up temporary files and free disk space. -
Remove log files – Use
DEL /S *.logto delete log files recursively across project directories or application folders. -
Clean up downloads – Use DEL with wildcards to remove unwanted downloaded files by type or pattern.
-
Delete backup files – Use
DEL *.bakorDEL *~to remove old backup files created by editors or applications. -
Clear cache directories – Use
DEL /Q /S cache\*.*to remove all cache files for application cleanup or troubleshooting. -
Remove build artifacts – Use DEL in build scripts to clean up compiled files, object files, and build outputs before fresh compilation.
-
Batch file cleanup – Use DEL in batch files to automate file deletion tasks, log rotation, or scheduled cleanup operations.
-
Delete files by age – Combine DEL with FORFILES to delete files older than a specific date:
FORFILES /D -30 /C "CMD /C DEL @path"deletes files older than 30 days. -
Clean up after installations – Use DEL to remove leftover installer files, temporary extraction directories, or installation logs.
-
Remove duplicate files – Use DEL in scripts that identify and remove duplicate files based on checksums or naming patterns.
-
Delete files matching patterns – Use DEL with complex wildcards to remove files matching specific naming conventions or patterns.
-
Automated disk space management – Use DEL in scheduled tasks to automatically remove old files, logs, or temporary data to maintain available disk space.
Tips and Best Practices
-
Always verify before deletion – Use
DIR patternto preview files before runningDEL pattern. This prevents accidental deletion of wrong files, especially with wildcards. -
Use /P for safety – When unsure, use
/Pto preview and confirm each file before deletion:DEL /P *.txt. This allows selective deletion. -
DEL bypasses Recycle Bin – Deleted files are permanently removed without recovery through Windows Explorer. Use file recovery software immediately if you accidentally delete important files.
-
Quote paths with spaces – Enclose paths containing spaces in double quotes:
DEL "My File.txt"orDEL "C:\My Documents\*.tmp". -
Preview with DIR – Always run
DIRwith the same wildcard pattern before DEL:DIR *.tmpthenDEL *.tmp. This shows exactly which files will be deleted. -
DEL cannot delete directories – Use
RMDIR /S directoryorRD /S directoryto delete folders. Attempting to use DEL on a directory produces "Access is denied." -
Combine with IF EXIST – In scripts, check file existence before deletion:
IF EXIST file.txt DEL file.txt. This prevents errors when files don't exist. -
Use /F carefully – The
/Fparameter bypasses read-only protection. Ensure you intend to delete read-only files before using/F. -
Test in safe directory first – Practice DEL commands in a test directory with sample files before running them on production data.
-
Use /Q in automated scripts – Add
/Qto suppress confirmation prompts in batch files and scheduled tasks:DEL /Q /S *.tmp. -
Understand wildcard behavior –
*.*matches all files,*.matches files without extensions, and*alone matches all files. Test wildcards with DIR first. -
Close programs using files – DEL fails with "Access is denied" if files are open in applications. Close programs before attempting deletion.
Troubleshooting Common Issues
"Access is denied" Error
Problem: DEL fails with "Access is denied" when trying to delete files.
Cause: Insufficient permissions, file is in use by another program, file has read-only attribute, or attempting to delete system/hidden files without appropriate parameters.
Solution:
- Close programs using the file (check Task Manager)
- Run Command Prompt as Administrator for system files
- Use
/Fto force deletion of read-only files:DEL /F filename - Clear read-only attribute first:
ATTRIB -R filenamethenDEL filename - Use
/A:Hto delete hidden files:DEL /A:H filename - Check if file is locked with Resource Monitor or Process Explorer
Prevention: Run CMD as Administrator when deleting system files. Verify files aren't in use before deletion.
"The system cannot find the file specified"
Problem: DEL reports it cannot find the specified file.
Cause: File doesn't exist, incorrect path, typo in filename, or file is hidden and you're not using /A:H.
Solution:
- Verify the file exists with
DIR filename - Use
DIR /A:Hto list hidden files - Check for typos in the filename or path
- Use Tab completion to auto-complete filenames
- Enclose paths with spaces in double quotes
Prevention: Use DIR to verify files exist before attempting deletion. Copy paths from Explorer to avoid typos.
DEL Deletes Wrong Files
Problem: DEL removes more files than intended when using wildcards.
Cause: Wildcards match more files than expected, or you're in the wrong directory.
Solution:
- Always preview with
DIR patternbeforeDEL pattern - Use more specific wildcards:
DEL report-2026-*.txtinstead ofDEL *.txt - Verify current directory with
CDbefore running DEL - Use
/Pfor confirmation:DEL /P *.txtto review each file
Prevention: Test wildcard patterns with DIR first. Use specific patterns to avoid over-matching.
Cannot Delete Files in Subdirectories
Problem: DEL doesn't remove files in subdirectories, only the current directory.
Cause: Without /S, DEL only operates on the current directory.
Solution:
Use /S to delete recursively:
DEL /S *.log
Or navigate to each subdirectory:
CD subdirectory
DEL *.log
Prevention: Use /S when you need to delete files across directory trees. Always preview with DIR /S pattern first.
"Are you sure (Y/N)?" Prompt Won't Go Away
Problem: DEL prompts for confirmation even in scripts.
Cause: Using *.* wildcard triggers automatic confirmation prompt as a safety feature.
Solution:
Use /Q to suppress the prompt:
DEL /Q *.*
Or pipe "Y" to the command:
ECHO Y | DEL *.*
Prevention: Always use /Q in automated scripts when deleting multiple files.
DEL Doesn't Delete Hidden or System Files
Problem: DEL skips hidden or system files without errors.
Cause: By default, DEL doesn't delete files with hidden or system attributes.
Solution:
Use /A to target hidden or system files:
DEL /A:H *.tmp
DEL /A:S *.sys
DEL /A:HS *.*
Prevention: Use /A with appropriate attributes when you need to delete hidden or system files.
Related Commands
RMDIR / RD – Remove Directories
RMDIR (or RD) deletes directories and their contents. Use when you need to remove folders, not just files.
Key difference from DEL:
- RMDIR deletes directories and optionally their contents with
/S - DEL deletes only files
Example:
RMDIR /S /Q C:\Temp\OldProject
Deletes the OldProject directory and all files/subdirectories without confirmation.
When to use: Removing entire directory trees, cleaning up project folders, or deleting empty directories.
ERASE – Identical to DEL
ERASE is an exact alias for DEL—both commands are identical in syntax and behavior. Use whichever you prefer; most users choose DEL for brevity.
Example:
ERASE file.txt
DEL file.txt
Both commands produce identical results.
FORFILES – Delete Files by Date
FORFILES selects files based on date criteria and executes commands on them. Use with DEL to delete files older than a specific date.
Example:
FORFILES /P C:\Logs /D -30 /C "CMD /C DEL @path"
Deletes files in C:\Logs older than 30 days.
When to use: Automated log rotation, cleaning up old backups, or maintaining disk space by removing aged files.
ATTRIB – Modify File Attributes
ATTRIB changes file attributes (read-only, hidden, system, archive). Use before DEL to remove attributes preventing deletion.
Example:
ATTRIB -R -H file.txt
DEL file.txt
Clears read-only and hidden attributes, then deletes the file.
Integration: Use ATTRIB to prepare files for deletion when they have restrictive attributes.
WHERE – Locate Files
WHERE searches for files in the current directory and PATH. Use to find files before deleting them.
Example:
WHERE /R C:\Projects *.tmp
Lists all .tmp files in C:\Projects and subdirectories. Review the list, then delete with DEL.
When to use: Finding files to delete across complex directory structures.
CIPHER – Secure File Deletion
CIPHER with /W securely wipes deleted file data from free space. Use after DEL to prevent file recovery.
Example:
DEL sensitive.txt
CIPHER /W:C:\
Deletes the file, then overwrites free space to prevent recovery tools from restoring it.
When to use: Deleting sensitive files where data recovery must be prevented (financial records, personal data, confidential documents).
Frequently Asked Questions
What does DEL /Q do?
DEL /Q enables quiet mode, suppressing confirmation prompts when deleting multiple files with wildcards. Without /Q, DEL asks "Are you sure (Y/N)?" when using *.* or similar patterns. Use /Q in automated scripts to avoid manual intervention: DEL /Q *.tmp or DEL /Q /S *.log.
How do I recover files deleted with DEL?
DEL permanently deletes files without sending them to the Recycle Bin. Recovery requires third-party file recovery software (Recuva, PhotoRec, TestDisk) and is not guaranteed—success depends on whether the disk space has been overwritten. For critical files, create backups before deletion or use Windows Explorer's Recycle Bin instead of DEL.
What is the difference between DEL and ERASE?
There is no difference; DEL and ERASE are identical commands. ERASE is simply an alias for DEL. Both accept the same syntax and parameters and produce identical results. Most users prefer DEL for brevity, but ERASE is available for compatibility with older scripts.
Can DEL delete directories?
No, DEL only deletes files. To delete directories, use RMDIR /S directory or RD /S directory. Attempting to use DEL on a directory produces an "Access is denied" error. Use RMDIR for folders and DEL for files.
How do I delete all files except certain types?
DEL doesn't have a built-in exclude option. Use multiple DEL commands for specific types, or use a FOR loop in a batch script with conditional logic:
FOR %f IN (*.*) DO IF NOT "%~xf"==".txt" DEL "%f"
This deletes all files except .txt files. Alternatively, use PowerShell's Remove-Item with -Exclude.
Why does DEL fail with "Access is denied"?
This error occurs when you lack permissions to delete the file, the file is in use by another program, or the file has read-only, system, or hidden attributes. Solutions: Close programs using the file, run CMD as Administrator, use DEL /F to force deletion of read-only files, or use ATTRIB -R -H -S to clear restrictive attributes.
Can I delete files on network drives?
Yes, DEL works with UNC network paths and mapped network drives: DEL \\server\share\file.txt or DEL Z:\file.txt for mapped drives. Ensure you have delete permissions on the network share. Network file deletion may be slower than local deletion.
What does DEL /F do?
DEL /F forces deletion of read-only files, bypassing read-only protection. Without /F, DEL skips read-only files with "Access is denied" errors. Use /F when you need to delete protected files: DEL /F *.bak. Be cautious—read-only files are often protected for a reason.
How do I delete hidden files?
Use /A:H to delete hidden files: DEL /A:H *.tmp. Without /A:H, DEL skips hidden files by default. To delete all files including hidden: DEL /A *.tmp. To list hidden files first: DIR /A:H.
Can I undo a DEL command?
No, DEL permanently deletes files without sending them to the Recycle Bin—there is no built-in undo. Use file recovery software immediately if you accidentally delete important data, or restore from backups. For recoverable deletion, use Windows Explorer's delete function instead of DEL.
What does DEL . do?
DEL *.* deletes all files in the current directory. Windows prompts "Are you sure (Y/N)?" as a safety feature. Use DEL /Q *.* to suppress the prompt. This is one of the most dangerous commands—always verify you're in the correct directory with CD before running it.
How do I delete files older than a certain date?
Use FORFILES with DEL:
FORFILES /P C:\Logs /D -30 /C "CMD /C DEL @path"
This deletes files older than 30 days. Adjust /D -30 to your desired age (negative numbers = older than, positive = newer than).
Quick Reference Card
| Command | Purpose | Example Use Case |
|---|---|---|
DEL file.txt | Delete single file | Remove specific file |
DEL *.tmp | Delete by extension | Clean temp files |
DEL /Q *.log | Delete without prompts | Automated cleanup |
DEL /F readonly.txt | Force delete read-only | Remove protected files |
DEL /S *.bak | Delete recursively | Clean all subdirectories |
DEL /P *.txt | Delete with confirmation | Safe selective deletion |
DEL /A:H *.tmp | Delete hidden files | Remove hidden temps |
DEL /A:-R *.* | Delete except read-only | Preserve protected files |
DEL /Q /S *.log | Recursive silent delete | Script cleanup |
DIR *.tmp then DEL *.tmp | Preview then delete | Safe deletion workflow |
Try DEL Command Now
Ready to practice deleting files safely? Use our Windows Command Simulator to run DEL commands in your browser without risk. No installation required—practice DEL, wildcard operations, attribute filtering, and recursive deletion in a safe environment. Perfect for learning, training, or testing command sequences before running them on production systems.
Explore the full Commands Reference for more Windows CMD utilities, including file management (COPY, MOVE, REN), directory operations (MKDIR, RMDIR, CD), and system administration commands.
Summary
The DEL command is the essential Windows tool for permanently deleting files from the command line. Use DEL to remove single files, delete multiple files with wildcards, or clean up directories recursively with /S. Combine /Q for silent deletion in scripts and /F to force removal of read-only files.
Remember that DEL bypasses the Recycle Bin, making deletion permanent and irreversible through standard Windows interfaces. Always verify file selections with DIR before deletion, use /P for confirmation when unsure, and maintain backups of critical data.
Master DEL for system administration tasks like log cleanup, temporary file removal, build artifact deletion, and automated disk space management. Understanding DEL's parameters, attribute filters, and safety practices ensures efficient file management while preventing accidental data loss in Windows environments.