AI Hints
Home›Linux Tutorial›Copy, Move, Remove
Linux · Lesson 27 of 120

rm: Removing Files

Deleting, carefully.

⏱ 2 min read▶ Video at 32:51🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Deleting files in the terminal is easy. Too easy, some people say. Because there's one big difference from deleting with a mouse. There's no recycle bin.

rm: Removing Files
From the video: rm: Removing Files
  • Deleting is easy
  • Maybe too easy
  • There's no recycle bin

Removing a file

RM, short for remove, deletes a file. RM to do dot TXT, and it's gone. Not moved to a bin. Really gone. If you try to remove a file that doesn't exist, RM tells you so.

Terminal
rm todo.txt
ls
Documents  Downloads  Music  Pictures  notes.txt
rm todo.txt
rm: cannot remove 'todo.txt': No such file or directory

Asking first

Dash I makes RM ask before deleting each file. It's a good habit while you're learning. Here RM asks, remove regular file notes dot TXT? We type Y, for yes, and press Enter, and the file is deleted. Typing N, for no, would have kept it.

Terminal
rm -i notes.txt
rm: remove regular file 'notes.txt'? y
ls
Documents  Downloads  Music  Pictures  todo.txt

Safe deleting habits

A few habits will keep your files safe. Run LS first, with exactly the same name, to see what you're about to delete. Use dash I while you're learning. Keep backups of anything important. And never type a delete command you don't fully understand, even if a website tells you to.

ls firstcheck the name
rm -iask before deleting
Backupsfor anything important
Understand itbefore you press Enter

Summary

RM deletes files for good, there's no undo, and dash I asks first. Next, deleting folders, and the one command you must be careful with.

Key takeaways
  • rm <file>
  • No recycle bin
  • rm -i asks
Next up: Removing Folders — rmdir and rm -r