Forrest logo
back to the rm tool

rm:tldr:9f11c

rm: Remove specific files and directories [r]ecursively.
$ rm -r ${filename_or_directory1 filename_or_directory2 ---}
try on your machine

The command "rm -r" is used to remove files or directories recursively, meaning it deletes both the specified file or directory and all its subdirectories and contents.

The notation "${filename_or_directory1 filename_or_directory2 ---}" indicates that you can include multiple filenames or directories separated by spaces. The "---" part denotes that you can continue listing filenames or directories as per your requirement.

For example, if you have the following command: rm -r file1.txt dir1/

It will remove the file named "file1.txt" and the directory named "dir1" including all its contents.

If you have more items to delete, you can add them to the command like this: rm -r file1.txt dir1/ file2.txt dir2/

This will delete "file1.txt", "dir1" and its contents, "file2.txt", "dir2" and its contents, and so on.

Please note that the "-r" flag is important when using the "rm" command to delete directories. It ensures that the deletion is performed recursively. Be cautious while using this command as it permanently deletes files and directories, and there is no way to recover them once they are gone.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.

Questions that are answered by this command:

  • How to I delete Directories?
back to the rm tool