Back to course

25. Deleting Directories and Contents: `rm -r` (The Danger Zone)

Linux Basics: From Zero to CLI Hero

Removing Non-Empty Folders

To remove a directory and all of its contents (files and subdirectories), you must combine rm with the recursive option (-r).

The rm -r Command

bash $ rm -r junk_project

This command executes silently and immediately deletes everything inside junk_project.

The Force Option (-f)

The -f (force) option suppresses all warnings and interactive prompts. The combination rm -rf is notoriously powerful and dangerous, especially when run as the root user or pointing to the wrong path. Never use rm -rf / unless you absolutely know what you are doing (which is probably destroying your system).

Safe Practice

Always combine interactive and recursive options for safety when deleting directories:

bash $ rm -ir large_directory_to_delete