HowTo: Deleting Directories in Linux

To delete a directory in Linux, you can use the rmdir command. However, if the directory is not empty, you will get an error message. To delete a directory and all its contents, including any subdirectories and files, you can use the rm command with the -r (recursive) option. For example:

rm -r directory_name

Note that using the rm -r command is irreversible and can be dangerous, as it will delete everything without asking for confirmation. To avoid accidental deletion, you can use the -i (interactive) option, which will prompt you for confirmation before deleting each file:

rm -ri directory_name

It’s always a good idea to double-check the contents of the directory before using the rm command, especially if you’re using the -r option.

Leave a Comment