Curious Minds

Clear answers to science and history questions

How to Delete a File in CMD Prompt: Step-by-Step

· 5 min read · Science

To delete a file in Command Prompt, open the prompt, navigate to the folder containing the file (or use its full path), and run the del command followed by the file name. For example, del report.txt removes that file from the current directory. The command deletes files permanently without sending them to the Recycle Bin, so check the path and name carefully before you press Enter. This guide covers the exact steps, the options that make deletion safer or more forceful, and what to do when Windows refuses.

What You'll Need

  • A Windows PC with Command Prompt available (it is built into Windows).
  • The exact name and location of the file you want to delete.
  • Basic awareness that del bypasses the Recycle Bin — there is no undo.
  • Administrator rights if the file sits in a protected system folder.

Step-by-Step

  1. Open Command Prompt. Press the Windows key, type cmd, and choose Command Prompt from the results. For files in protected locations, right-click and select Run as administrator.
  2. Check where you are. The prompt shows your current directory, for example C:\Users\YourName>. The del command acts on this folder unless you give a full path.
  3. Navigate to the file's folder (optional). Use cd followed by the path, such as cd Documents\Reports. If the path contains spaces, wrap it in quotes: cd "C:\My Documents\Reports". You can also skip this step and type the full path in the delete command.
  4. List the folder contents to confirm the name. Type dir and press Enter. This shows every file and folder in the current directory. Compare the name exactly — Windows filenames are not case-sensitive, but spelling and extensions must match.
  5. Run the delete command. Type del filename.ext and press Enter. For example, del notes.txt. To delete from another location without navigating, use the full path: del "C:\Users\YourName\Documents\notes.txt".
  6. Confirm the result. Run dir again. If the file no longer appears, it is deleted. Command Prompt normally prints no message on success, which can be confusing — the absence of an error means it worked.
  7. Use options only when needed. Add /p to be asked for confirmation before each file is deleted (del /p notes.txt). Add /f to force deletion of read-only files (del /f notes.txt). Add /s to delete matching files in all subfolders, and /q to suppress confirmation prompts when used with /s. Combine carefully: del /s /q *.tmp removes every .tmp file in the tree without asking.
  8. Delete multiple files or use wildcards. del *.txt deletes all .txt files in the current folder. del *.* targets everything in the folder and will prompt for confirmation unless /q is added. Preview wildcard matches with dir *.txt first so you know exactly what will go.
  9. Remove an empty folder (if that was the goal). del removes files, not folders. Use rmdir (or rd) for an empty directory, and rmdir /s /q to remove a folder and its contents. This is a separate, more destructive command — double-check the path.

Common Mistakes

  • Assuming the Recycle Bin is a safety net. Files deleted with del from Command Prompt skip the Recycle Bin entirely. There is no built-in undo.
  • Forgetting the extension. del notes will not match notes.txt unless you type the extension or use a wildcard.
  • Running wildcards in the wrong folder. del *.* in C:\Windows or your user profile can remove far more than intended. Always run dir first.
  • Leaving out quotes around paths with spaces. del C:\My Documents\notes.txt is read as two separate arguments and fails. Use del "C:\My Documents\notes.txt".
  • Confusing del with rmdir. del does not remove folders; trying it produces an error or, with wildcards, unexpected results.
  • Ignoring the confirmation prompt. When del *.* asks “Are you sure (Y/N)?”, pressing Y without reading is a common way to lose files.

Tips

  • Use Tab completion: type the first few letters of a filename and press Tab to cycle through matching names, avoiding typos.
  • Wrap any path containing spaces in double quotes, every time.
  • Test destructive wildcards with dir using the same pattern before switching to del.
  • For important files, move them to a backup folder first with move, then delete after confirming.
  • Remember that del /s searches subfolders too — a pattern that looks harmless at the top level can match files deep in the tree.
  • If you need a confirmation step for a batch of files, /p is your friend; it asks before each deletion.

Troubleshooting

  • “Access is denied.” The file may be read-only, in use by another program, or in a protected location. Close the program using it, try del /f, or reopen Command Prompt as administrator.
  • “The system cannot find the file specified.” Check the spelling, the extension, and your current directory. Run dir to see what is actually there, and confirm you are in the right folder with cd.
  • “The process cannot access the file because it is being used by another process.” A program still has the file open. Close it, or restart the PC and try again.
  • Nothing seems to happen. That is normal on success — del is silent. Run dir to verify the file is gone.
  • You deleted the wrong file. Command Prompt deletion is permanent. Check the Recycle Bin anyway (files deleted through Explorer may be there), then look at File History or a backup if one was configured. Otherwise, recovery requires third-party tools and is not guaranteed.
  • Wildcard deleted too much. Stop immediately and avoid writing new data to the drive; recovery odds drop as new files overwrite the space.

Frequently Asked Questions

Does del send files to the Recycle Bin?

No. Files deleted from Command Prompt are removed directly and do not appear in the Recycle Bin.

Can I undo a del command?

There is no built-in undo. Recovery depends on backups or third-party recovery software, and success is not guaranteed.

How do I delete a file with spaces in its name?

Wrap the full name or path in double quotes, for example del "my report.txt".

What is the difference between del and erase?

They are effectively the same command; erase is an alias for del and accepts the same options.

Can del remove a folder?

No. Use rmdir or rd for folders, adding /s to include contents.

Why does del *.* ask for confirmation?

Because it matches every file in the folder, Command Prompt prompts as a safety check. Adding /q suppresses the prompt — use it only when you are certain.

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions