•Arnošt Havelka
Removing Files and Directories
Learn rm and rmdir to delete files and directories safely.
Start Interactive LessonThe rm command deletes files permanently. Use it carefully—there's no trash can in the terminal!
Remove a Single File
Use rm filename to delete a file.
Try the command
Delete a file!
Build the command
rmfilename
Choose a command
Terminal
C:\Users\User>rm old.txt
Delete instantly:
Command Prompt
important.txt
trash.txt
C:\Users\User>ls
Remove Multiple Files
Delete several files at once by listing them.
Try the command
Delete multiple files!
Build the command
rmfile1 file2 file3
Choose a command
Terminal
C:\Users\User>rm temp1.txt temp2.txt temp3.txt
Batch deletion:
Command Prompt
keep.txt
delete1.txt
delete2.txt
C:\Users\User>ls
Remove Empty Directories: rmdir
The rmdir command removes empty directories. It refuses to delete non-empty ones.
Try the command
Delete an empty directory!
Build the command
rmdirdirectory
Choose a command
Terminal
C:\Users\User>rmdir empty_folder
Remove empty folders:
Command Prompt
Project/
EmptyFolder/
ls EmptyFolder/
C:\Users\User>ls
Remove Directories with Contents: rm -r
Use rm -r to delete directories and all their contents. Be very careful with this!
Try the command
Delete a directory with files!
Build the command
rm-rdirectory
Choose a command
Terminal
C:\Users\User>rm -r old_project
Delete entire trees:
Command Prompt
Project/
ls Project/
C:\Users\User>ls
Knowledge Check
1 / 3What does rm do?
References
These documentation links provide authoritative details for the commands used in this article.
Up Next
Practice: File Organization
Practice organizing files using mkdir and mv commands.