A command prompt deletes a file by passing the file's name to a delete command—del or erase in Windows Command Prompt, rm in macOS and Linux shells, and Remove-Item in PowerShell—which asks the operating system to remove that file's directory entry and free its storage space. The command itself does very little; the real work is done by the operating system's file-management services. Understanding that division of labor explains almost everything else about how command-line deletion behaves: why the file sometimes seems to vanish instantly, why it sometimes can't be deleted at all, and why it doesn't go to the Recycle Bin by default.
The phrase "command prompt" is used loosely. On Windows it usually means the classic Command Prompt (cmd.exe). On macOS and Linux, the equivalent is a terminal running a shell such as Bash or Zsh. PowerShell is a separate, more capable Windows shell with its own syntax. The underlying principle is the same in all of them, but the exact commands and their defaults differ in ways that matter, so this article treats them separately where the distinction changes the answer.
What "deleting" actually means at the operating system level
A file on disk has two parts: the data blocks that hold its contents, and a directory entry (sometimes called a link or record) that maps a name to those blocks, along with metadata such as permissions, timestamps, and size. When you delete a file from the command line, the command does not usually overwrite the data. It asks the file system to remove the name-to-data association.
Once the directory entry is gone, the file is unreachable through any path, and the file system marks its data blocks as available for reuse. The contents may physically remain on the disk for some time, which is why recovery tools can sometimes resurrect deleted files and why secure erasure requires more than an ordinary delete. The operating system also enforces permissions: a delete request succeeds only if your user account has the right to modify the directory that contains the file (on Unix-like systems) or the appropriate access on Windows. This is why a file can be readable but not deletable, and why "permission denied" is one of the most common deletion errors.
Deleting files in Windows Command Prompt
In cmd.exe, the primary command is del, with erase as a fully equivalent synonym. The basic form is:
Quotes are optional for simple names but essential when the path contains spaces. If you run del with just a filename and no path, it acts on the current working directory, which the prompt displays before the > symbol. This is the single most common source of confusion: users type del report.docx, get "Could Not Find," and assume the command is broken when the file is simply in a different folder. Supplying the full path, or changing directory first with cd, resolves it.
Several behaviors of del surprise people coming from the graphical interface:
No Recycle Bin. del removes the file directly. It does not move it to the Recycle Bin, so there is no easy undo. Recovery depends on file-recovery software and on how much new data has been written to the disk since. Wildcards are accepted. del *.tmp deletes every matching file in the current directory, and del . deletes everything the command can. These run without a confirmation prompt by default, which makes a mistyped wildcard genuinely dangerous. Directories are not deleted. del targets files. Pointing it at a folder produces an error or, with wildcards, deletes the files inside rather than the folder itself. Removing a directory requires rmdir (or rd). Prompts for confirmation. By default, del asks "Are you sure (Y/N)?" when you use a wildcard that matches many files. The /Q switch turns that prompt off, and /F forces deletion of read-only files. Missing files are silent. del reports an error for a file it cannot find but does not stop a batch script unless you check the error level yourself.
A related command, rmdir /s /q, deletes an entire directory tree, files included, without prompting. It is powerful and unforgiving, and there is no built-in undo.
Deleting files in macOS and Linux terminals
On Unix-like systems the command is rm, short for remove. The basic form is:
The tilde expands to your home directory, and paths can be absolute (/Users/alex/...) or relative to where the terminal is currently sitting. Unlike Windows del, rm is quiet on success—no output means the file is gone—and it reports an error for a missing file, which is a useful signal that you may have mistyped a path.
The defaults differ from Windows in important ways:
No Recycle Bin, no Trash. Files deleted with rm do not go to the macOS Trash or any equivalent. They are unlinked immediately. Directories require a flag. rm refuses to remove a directory unless you add -r (recursive), which deletes the folder and everything inside it. rm -rf combines recursion with -f (force), suppressing prompts and most errors. This combination is the canonical example of a command that can destroy a system or a home directory in one keystroke, and it deserves real caution. No confirmation by default. Many systems alias rm to rm -i for interactive confirmation, but you should not assume that. Check with alias rm if you are unsure. Wildcards are expanded by the shell, not the command. When you type rm *.log, the shell first replaces the pattern with the matching filenames and then passes that list to rm. This matters because a pattern that matches nothing can behave differently depending on the shell's settings.
Deleting files in PowerShell
PowerShell provides Remove-Item, with rm, del, and erase as aliases that map to it. The syntax is more verbose and more consistent:
PowerShell's behavior sits between cmd.exe and a Unix shell. It does not use the Recycle Bin by default, it supports wildcards, and it can remove directories and their contents with -Recurse. It also supports -WhatIf, which reports what would be deleted without actually deleting it—a genuinely useful safety net for scripts. Because PowerShell aliases shadow the older commands, typing del inside PowerShell runs Remove-Item, not the cmd.exe version, which can produce subtly different results.
Why deletions fail, and what the error means
Most command-line deletion failures fall into a few recognizable categories.
The file is in use. On Windows, a file open in another program—or locked by a process—cannot be deleted, and you get a sharing violation. On Unix-like systems, an open file can often be unlinked successfully; it simply disappears from the directory while the running process keeps its handle, and the space is reclaimed when the process closes it. This is a fundamental difference in how the two systems handle open files.
Permissions are insufficient. You may lack write permission on the containing directory, or the file may be marked read-only. Windows offers del /F; Unix offers sudo rm, which should be used with real care because it can delete protected system files.
The path is wrong. A relative path resolves against the current directory, which may not be where you think. Quoting problems with spaces, or a stray backslash or forward slash depending on the platform, also cause "not found" errors.
The name is reserved or the filesystem objects. Windows reserves names like CON and NUL, and a file can be protected by attributes such as system or hidden. These require additional flags or attribute changes.
The directory is not empty. rm without -r and rmdir without /s refuse to remove a folder that still contains files.
Distinctions that change the answer
The most consequential distinction is between deleting and destroying. A command-line delete removes the reference to the data, not the data itself. If the file contained sensitive information, ordinary del or rm is not a secure erasure; the blocks may persist until overwritten. Tools designed for secure deletion overwrite data before removing it, but their effectiveness depends on the storage medium—solid-state drives and wear-leveling complicate this considerably.
The second distinction is between interactive and scripted use. The commands described here are what people type by hand, but they also appear inside batch files, shell scripts, and scheduled jobs, where no one is watching. In that context, the absence of a confirmation prompt is a feature and a hazard at once. Scripts should use explicit paths, check error levels or exit codes, and prefer safe testing flags such as PowerShell's -WhatIf before running deletion steps for real.
The third distinction is the Recycle Bin and Trash question. Users often assume the command line offers the same safety net as the desktop. It generally does not. If you want a recoverable delete from the command line, you need to use a tool or API that explicitly moves files to the Recycle Bin or Trash, or you should delete through the graphical interface instead. Treating a command-line delete as reversible is the mistake most likely to cost someone a file.
Finally, the answer depends on which shell you are actually in. A user who opens "Terminal" on Windows may land in PowerShell, where del means something different from what it means in cmd.exe. When a deletion command behaves unexpectedly, the first thing to confirm is the shell, the current directory, and the exact path being targeted—before running it again with more force.