rm
rm linux command cheatsheet by Thamizhiniyan C S
Introduction
The rm command is used to remove files or directories.
Syntax
rm [OPTION]... [FILE]...
Important Flags
-f
Forces the removal of all files or directories.
-i
Prompts for confirmation before removing.
-I
Prompts once before removing more than three files or when removing recursively.
-r
Removes directories and their content recursively.
-d
Removes empty directories.
-v
Provides a verbose output.
--help
Displays the help text.
--version
Displays the command version.
Examples
rm a.txtRemoving one file at a time.
rm b.txt c.txtRemoving more than one file at a time.
rm -d ExampleTo remove an empty directory.
rm -- [directory name]To remove a directory whose name starts with a hyphen (-).
rm -- -file.txtRemoves a file whose name starts with a hyphen (-).
rm -r ExampleTo delete a directory that contains subdirectories and files (Recursive Deletion)
rm -r -v ExampleTo delete a directory that contains subdirectories and files (Recursive Deletion), and the -v flag to list each step of the process.
rm -r *-r : Deletes all files and sub-directories recursively in the parent directory.
rm -i d.txtAsks for confirmation before removing each file (Interactive Deletion).
rm -d -i ExampleUse the -i option to display a prompt asking for confirmation before removing a directory.
rm -f e.txtOverrides write protection and removes the file forcefully (Force Deletion).
rm -d ExampleRemove a write-protected directory.
rm -d -f ExampleTo avoid confirmation when deleting a directory.
sudo rm -d ExampleElevate command privileges to remove a write-protected directory.
rm -rf Use this command to remove a write-protected directory that contains other files and directories.
rm --versionDisplays the version of rm currently running on the system.
Last updated
Was this helpful?