The basic command to delete a file

To delete a file in terminal, type rm followed by the filename, then press Enter. For example, to delete a file called notes.txt, you would type rm notes.txt and press Enter. The file disappears when ready — there is no trash or recycle bin to recover it from.

The rm command works the same way on Mac, Linux, and Windows (if you are using PowerShell or Windows Subsystem for Linux). On older Windows command prompt, the command is del instead, but the idea is identical.

Before you press Enter, make sure you are in the correct folder and that you have spelled the filename exactly right. Once you delete a file this way, it is gone for good — most terminal applications do not offer an undo.

Key Takeaways

  • The rm command deletes a file permanently; there is no recovery option like a trash bin.
  • You must be in the same folder as the file, or type the full path to the file, for the command to work.
  • Use rm -i filename to ask for confirmation before deleting, which prevents accidental loss.
  • To delete a folder and everything inside it, use rm -r foldername, but only after checking what is inside.

Making sure you are in the right folder

Terminal deletes files from wherever you are currently located. If you type rm notes.txt but you are in your Documents folder and the file is on your Desktop, nothing happens — the command just says the file is not found.

Before you delete, use pwd to see which folder you are in, and ls to list the files in that folder. This takes five seconds and prevents you from deleting the wrong file. Once you see the filename listed exactly as it appears, you know you are in the right place.

If the file is in a different folder, you can either navigate to it first using cd foldername, or type the full path: rm /Users/yourname/Desktop/notes.txt (on Mac) or rm C:\Users\yourname\Desktop\notes.txt (on Windows PowerShell).

Adding confirmation so you do not delete by accident

The safest way to delete is to add -i to the command: rm -i notes.txt. This makes terminal ask "remove notes.txt?" before it actually deletes. You type y and press Enter to confirm, or n and press Enter to cancel.

This extra step takes one second and saves you from deleting the wrong file because you mistyped the name or were in the wrong folder. Many people add this as a habit, especially when they are new to terminal.

Deleting multiple files at once

You can delete several files in one command by listing them all: rm file1.txt file2.txt file3.txt. Terminal deletes all three when you press Enter.

You can also use a wildcard to delete files that match a pattern. For example, rm *.txt deletes every file ending in .txt in the current folder. Be very careful with wildcards — they delete everything that matches, and you cannot undo it. Always use rm -i *.txt instead, so you get asked about each file.

Deleting folders and everything inside them

The regular rm command does not delete folders, only files. To delete a folder and all the files and subfolders inside it, use rm -r foldername. The -r stands for "recursive," meaning it goes into the folder and deletes everything.

This is powerful and dangerous. Before you run rm -r, use ls foldername to see what is actually inside. If you are not sure, use rm -ri foldername instead — the -i makes terminal ask you about each file and folder before deleting, so you can stop if you see something you want to keep.

What happens after you delete

Once you press Enter and confirm (if you used -i), the file or folder is gone. Terminal does not move it to a trash bin or create a backup — it removes it from the file system. Some operating systems may recover deleted files using special software, but this is not may provide and becomes harder the more you use your computer afterward.

If you delete something by accident, stop using your computer and contact a data recovery service when ready. The longer you wait and the more you do on the computer, the less likely recovery becomes.

Frequently Asked Questions

Can I undo a delete in terminal?

No. Once you press Enter and the file is deleted, it is gone. There is no undo command in terminal. This is why using rm -i to ask for confirmation is a good habit, especially when you are learning.

What if I delete a file I need?

If you have a backup or the file is in a cloud service like Google Drive or Dropbox, you may be able to restore it from there. Otherwise, you would need to contact a data recovery specialist. Prevention is much easier than recovery.

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

Put the filename in quotes: rm "my notes.txt". Without quotes, terminal thinks each word is a separate filename and tries to delete multiple files, which fails.

Is there a difference between rm and del?

On Mac and Linux, use rm. On Windows command prompt (the older terminal), use del for files and rmdir for folders. On Windows PowerShell (the newer terminal), rm works and is the same command.

Can I delete a file that is currently open?

On Mac and Linux, yes — the file deletes even if a program has it open. On Windows, usually no — the file is locked while it is in use, and the delete command fails. Close the file first, then delete it.