rm Command: Tutorial & Examples
Delete files and directories
rm command is a Linux utility that stands for "remove." It is used to delete files and directories from the file system.
To use the
rm command, you will need to specify the name of the file or directory that you want to delete. For example, to delete a file named
file.txt, you would use the
To delete a directory and all of its contents, you can use the
-r option to specify that the
rm command should operate recursively. For example, to delete a directory
mydir and all of its contents, you would use the following command:
rm -r mydir
It's important to note that the
rm command is a powerful tool and it can be dangerous to use if you are not careful. When you delete a file or directory with
rm, it is
permanently removed from the file system and cannot be recovered (or only with great difficulty). So be sure to use the
rm command with caution, and make sure that you have a
backup of any important files before deleting them.
There are also options available to the
rm command that allow you to force (
-f) the deletion of files, even if they are read-only, or to interactively confirm each file before
deleting it (
-i). These options can be helpful in certain situations, but be aware that they can also be dangerous if used improperly.