rm
Commandrm
The rm
command is used to remove files and directories in Linux. The most basic form of the command is:
rm [file_name]
This will remove the specified file or directory.
rm
rm
(Basic Usage)Removes a file. If it is a directory, you need additional flags:
rm file_name
rm -r
(Recursive Remove)Removes a directory and its contents recursively:
rm -r directory_name
This will remove the directory and all its files and subdirectories.
rm -f
(Force Remove)Forces the removal of files without prompting for confirmation, even if the file is write-protected:
rm -f file_name
rm -i
(Interactive Mode)Prompts for confirmation before each file removal:
rm -i file_name
rm -d
(Remove Empty Directories)Removes an empty directory:
rm -d directory_name
rm -v
(Verbose Output)Displays information about what is being done as files are being removed:
rm -v file_name
rm --help
(Show Help)Displays help information for the rm
command:
rm --help
rm -rf
(Force Recursive Remove)Combines -r
and -f
options to forcefully and recursively remove directories and files without prompting:
rm -rf directory_name
Option | Description |
---|---|
rm [file_name] |
Removes a file. |
rm -r [directory_name] |
Removes a directory and its contents recursively. |
rm -f [file_name] |
Forces the removal of a file without confirmation. |
rm -i [file_name] |
Prompts for confirmation before each file removal. |
rm -d [directory_name] |
Removes an empty directory. |
rm -v [file_name] |
Provides verbose output while removing files. |
rm -rf [directory_name] |
Forcefully and recursively removes a directory and its contents. |
rm --help |
Displays help information. |
For more detailed information, use the manual page for the rm
command:
man rm