How to remove a full directory in Linux

Updated: 11/16/2019 by Computer Hope
Tux the Linux penguin.

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

To remove a directory containing 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. Executing the command would recursively delete all files and subdirectories in that directory.

Note

By default, rm does not prompt you to confirm deletions. If rm deletes the files successfully, it displays no output, and silently returns exit status 0 (success).

To be prompted before deletions, use the -i option. To see a line of output for each deletion, use the -v (verbose) option. For complete options and examples, see our Linux rm command reference.