Delete a Directory Using the Linux rm Command

The Linux rm command as previously discussed, can be used to not only delete a file but a directory as well. The following command will delete an empty directory.

rm {Directory Name} -d

If you attempt to erase a directory that is not empty, then an error will be displayed as shown in the image. Here we attempted to delete the directory 'holds' which contains files. Use the following to delete a non-empty directory.

rm {Directory Name} -r

Delete Linux Directory Error

The same options used with rm to delete a file can also be used to delete a directory. E.g., rm {Directory Name} -dv will provide feedback as to the success of the deletion.