Delete a directory in Linux

Written by
Date: 2020-03-01 15:25:32 00:00

To delete a directory or folder in Linux you use the command

rmdir directoryname

But that command only works when the folder is empty, what to do if it still has files?

rm -rf directoryname

Just be sure you are not deleting anything you may need later, as this has no fallback option.

You can also use find to delete lots of directories matching a pattern

find . -type d -name "directoryname" -exec rm -rf {} +