How to remove a directory including all the subdirectories and files in Unix [Quick Tip]

Share this article

Problem:

Imagine a scenario where you want to delete a directory (lets say dir_name) which contains lots of subdirectories (folders) and files. You may encounter the following errors if you try rm or rmdir:

rm: cannot remove `dir_name': Is a directory

rmdir: failed to remove `dir_name': Directory not empty

cannot remove directory `dir_name’. Directory not empty

Solution:

To avoid this problem use the following command:

rm -rf dir_name

It will delete all the content of dir_name including the subdirectories.