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 immediately — there is no trash or recycle bin to recover it from.
The rm command works the same way on Mac, Linux, and most Unix-based systems. Windows PowerShell uses a different command, del or Remove-Item, but the principle is identical. Once you press Enter, the deletion is permanent and cannot be undone through normal means.
Key Takeaways
- Type rm filename to delete a single file, where filename is the exact name of the file you want to remove.
- Use rm -i filename to get a confirmation prompt before the file is deleted, which prevents accidental loss.
- Delete multiple files at once by typing rm file1 file2 file3 or using a pattern like rm *.txt to remove all files with a certain extension.
- Deleted files cannot be recovered from terminal — they do not go to trash, so double-check the filename before you press Enter.
Deleting a single file with confirmation
If you want terminal to ask you to confirm before deleting, add the -i flag: rm -i notes.txt. Terminal will print a message asking "remove notes.txt?" and you type y for yes or n for no, then press Enter.
This extra step takes one second but prevents the most common mistake — typing the wrong filename and losing a file you meant to keep. Many people set up their terminal to use rm -i by default, so they always get a chance to reconsider before any deletion happens.
Deleting multiple files at once
To delete several files in one command, list them all: rm file1.txt file2.txt file3.txt. Terminal deletes all three when you press Enter.
You can also use a wildcard pattern to delete files that match a certain name or extension. For example, rm *.txt deletes every file in the current folder that ends in .txt. The pattern rm temp* deletes every file whose name starts with temp. Always use rm -i with wildcards — it is easy to accidentally match more files than you intended, especially if you are working in the wrong directory.
Deleting files in a specific folder
If the file is not in your current folder, type the path to it. For example, rm ~/Documents/notes.txt deletes notes.txt from your Documents folder. The tilde (~) stands for your home directory.
You can also navigate to the folder first using cd (change directory), then delete the file. Type cd ~/Documents to move into Documents, then rm notes.txt to delete the file there. Use pwd (print working directory) to see which folder you are currently in before you run any delete command.
Avoiding common mistakes
The most dangerous mistake is using a wildcard pattern without thinking through what it matches. The command rm *.txt looks harmless, but if you are in the wrong folder, you could delete every text file on your computer. Always check your current folder with pwd before running a delete command with wildcards.
Another common error is mistyping the filename. Terminal does not warn you if the file does not exist — it simply says "No such file or directory" and does nothing. But if you type a filename that does exist, it deletes without hesitation. Use rm -i to force a confirmation step, or use ls (list) to see the exact filename before you type the delete command.
Deleting folders and their contents
The rm command deletes files, not folders. To delete a folder and everything inside it, use rm -r foldername. The -r flag stands for "recursive" and tells terminal to delete the folder and all its files and subfolders.
This is powerful and dangerous. rm -r with the wrong folder name can wipe out large amounts of data. Always use rm -ri foldername instead — the -i flag makes terminal ask for confirmation before deleting each item inside the folder, giving you a chance to stop if something looks wrong.
Frequently Asked Questions
Can I recover a file after I delete it with rm?
No. Files deleted with rm do not go to trash or a recycle bin — they are removed directly. Recovery is possible only with specialized data recovery software, and only if the disk space has not been overwritten. Do not rely on recovery. Always use rm -i to confirm before deleting.
What does the error "permission denied" mean?
Terminal is telling you that you do not have permission to delete that file. This usually means the file is owned by a different user or is protected. You can try sudo rm filename to delete it with administrator privileges, but this requires your password and should only be used if you are certain you own the file.
How do I delete a file with a space in its name?
Put the filename in quotes: rm "my notes.txt". Alternatively, you can use a backslash before the space: rm my\ notes.txt. Terminal treats the quoted or escaped name as a single filename instead of two separate words.
Is there a difference between rm and rm -f?
The -f flag stands for "force" and deletes without asking, even if the file is read-only or protected. rm -f is faster but more dangerous because it skips all warnings. Use rm -i instead — it is safer and only adds one confirmation step.