How do I remove a full directory in Linux?

Updated: 11/13/2018 by Computer Hope

LinuxWhen attempting to remove a directory using a command such as the rmdir, you may receive a prompt such as "rmdir: 'dir': Directory not empty" and be unable to delete the directory.

To remove a directory that contains other files or directories, use the following command.

rm -r mydir

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

Executing the above command would delete all files and directories in the directory named in the command. However, it would also present a prompt for approval to delete each of the files. If you don't want to receive a prompt for each file, use the following command instead.

rm -rf mydir

In the example above, the "mydir" directory, along with all files and directories in that directory, would be deleted with no prompt or message.

Additional information