Wondershare Recoverit

Hard Drive Recovery

  • Recovers deleted or lost files from hard drive effectively, safely and completely.
  • Supports data recovery from 500+ data loss scenarios, including computer crash, partition loss, accidental human error, etc.
  • Supports 1000+ file formats recovery with a high success rate and without any quality loss.
Free Download Free Download Free Download Learn More >
hard drive recovery

How to Delete Files Using Command Prompt and Command Line

Wondershare Recoverit Authors

Jan 15, 2024 • Filed to: Recover Files • Proven solutions

Regarding handling everyday tasks, the command line can turn out to be powerful as well as harmful. For instance, the rm command enables you to eliminate or delete files. The rmdir command works in the same manner for directories or folders.

However, you should be cautious because, unlike transferring files from the Finder to the Trash, it is not possible to retrieve them if you utilize these commands. Still, if you desire to use the Terminal’s powers, the command delete file is one command that you cannot ignore.

There are ways to include a safeguard to ensure that the only files you erase are truly the ones you want to delete.

Part 1. Advantages of Erasing Files Using the Command Line

It is not complicated to delete files using the Finder, and you are always able to recover files from Trash in case you want to change your mind. So why take the trouble to delete files using the command prompt and command line?

Below are several reasons to delete files Using Command Prompt and Command Line:

Part 2. Deleting Files and Folders Using Command Prompt on Windows

Are you aware that it is possible to erase a file on Windows by using the Command Prompt? Below are some steps on how to go about it:

Steps

How to use Command Prompt to delete files and folders

Run cmd to delete files and folders

Use cmd to delete files and folders

If you are not in the appropriate directory, you can type ‘cd’ to the directory or key in the complete file path to be erased.

Use cmd to complete file path to delete files and folders

For instance, in case you want to erase ‘file.txt’ you need to key in ‘del file.txt.’ If the file is situated on the desktop, key in ‘C: /Users/username/Desktopfile.txt’ in case you are one directory on top.

Use cmd to erase files and folders

Delete files and folders using Command Prompt

Video Tutorial on How to Recover Deleted Files on Windows 10/8/7 Easily?

Recent Videos from Recoverit

View More >

Part 3. Deleting Files/Folders Using the Command Line on Mac

Erasing folders or directories varies a bit. If you attempt to operate the rm command on a folder, the message below will appear:

Deleting files using command prompt and command line on Mac

You can't erase a directory utilizing the rm command. rmdir is a special command used to delete directories. Therefore, to erase a director called Archives, you need to operate the command below:

rmdir Archives

Part 4. Deleting a Directory as well as Files in it

rm -R Archives

Keep in mind that this is a permanent decision. You can, however, make use of the –flag for security.

rm -iR Archives

This will request you to verify the deletion of every item.

Part 5. Tips and Tricks for Using CMD Delete File

If you cannot empty your Mac’s trash, the rm – R command is useful. A file may be locked, or you might not be permitted to erase one or multiple files. This may be irritating; however, you can use the command line to get a simple solution.

1. Type as shown underneath in Terminal

2. Send the Output of a Command to the Clipboard

You will simply send the output straightaway to the clipboard.

delete files using command-Tips and Tricks for Using cmd delete file

From a folder, open the command prompt

You might have attempted to open the command prompt and encountered a lot of cd commands trying to access a folder. The good news is that you can save lots of time by using Explorer to open a command prompt inside a folder. You just need to hold shift, click right on a folder, and the context menu will present the option.

delete files using command-open the command prompt

Command History

Most probably, you might have been tapping the up key to access your earlier commands; this can be tiresome if you are attempting to get a specific command. Another method you can use to see your earlier command is using the donkey command.

Doskey/history

delete files using command-command history

If you lost data on your computer, don't worry! You still have the chance to get lost data back. To recover files from the computer, you can try the file recovery tool.

Recoverit author

Amy Dennis

staff Editor

Home > Resources > Recover Files > How to Delete Files Using Command Prompt and Command Line