How do I remove a full directory in Linux?

LinuxWhen attempting to remove a directory using a command such as the rmdir command, you may receive a prompt such as "rmdir: 'dir': Directory not empty" and be unable to delete the directory. To remove a directory that is full with other files or directories, use the below command.

rm -r directory

 In the above example, you would replace "directory" with the name of the full directory you want to delete. So if the directory was named files, you would type: rm -r files at the prompt.

Doing the above command would delete the files and directories, but would require a prompt for each of the files. If you also don't want to receive a prompt use the command below.

rm -rf example

In the above example, the "example" directory would be deleted with no prompt or message.

Additional information

  • See the rm and rmdir commands for further information about each of these commands and other available switches.