The rm
command in Bash is used to remove files and directories from the filesystem. It is a powerful command that permanently deletes the specified files, making them unrecoverable through normal means.
The basic syntax of the rm
command is as follows:
rm [options] [arguments]
-f
: Forcefully remove files without prompting for confirmation.-i
: Prompt for confirmation before each file is removed.-r
: Recursively remove directories and their contents.-v
: Verbosely show which files are being removed.Here are some practical examples of using the rm
command:
rm filename.txt
rm file1.txt file2.txt file3.txt
rm -f filename.txt
rm -i filename.txt
rm -r directory_name
rm -v filename.txt
-f
option, to avoid accidental data loss.-i
option when you’re unsure about the files you want to delete; it helps prevent mistakes.rm -r
with caution, as it will delete entire directories and their contents without recovery options.