Hosting or Servers Logo

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.

You Are Leaving Us

This link is being provided as a convenience and for informational purposes only it is not an endorsement or an approval of any of the products, services or opinions of the corporation or organization or individual.

Hostingorservers.com bears no responsibility for the accuracy, legality or content of the external site or for that of subsequent links.