Delete A File
Part of the Fundamentals section of Coddy's Terminal journey — lesson 14 of 82.
The rm command stands for remove. It permanently deletes a file from the filesystem.
Simply type rm followed by the filename:
rm readme.txtThe file is deleted immediately. You can confirm it is gone with ls.
Deleting multiple files at once:
rm file1.txt file2.txt file3.txtDeleting a folder and all its contents:
To delete an entire directory including everything inside it, use the -r flag (recursive):
rm -r documentsSafety flags:
-i — asks for confirmation before deleting each file:
rm -i readme.txt-f — force delete without any prompts (use with caution!):
rm -f readme.txtWarning: The terminal has no recycle bin. Files deleted with
rmare gone permanently and cannot be recovered. Always double-check before runningrm.
Challenge
BeginnerDelete the file readme.txt using the rm command, then use ls to confirm it has been removed.
Warning: Deleted files cannot be recovered in the terminal. Make sure you are deleting the correct file!
Cheat sheet
The rm command permanently deletes files from the filesystem:
rm readme.txtDelete multiple files:
rm file1.txt file2.txt file3.txtDelete a directory and its contents:
Use the -r flag (recursive):
rm -r documentsSafety flags:
-i — prompts for confirmation before deleting:
rm -i readme.txt-f — force delete without prompts:
rm -f readme.txtWarning: Files deleted with
rmare permanently removed and cannot be recovered.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline