How to delete a directory in Linux command line

When attempting to remove a directory in the command line on a Linux box you may receive an error “directory not empty” when trying to run

rmdir  thedirectorytodelete

The solution to this is to run

rm -rf thedirectorytodelete

This will force the directory and all the contents there in to be erased.

You will be asked if you wish to proceed

 

If you want to be asked for each file, then you would do

rm -r thedirectorytodelete

 

remember always to use caution when using  rm -rf as

rm -rf /

Would be disastrous.

 

Leave a Comment

Your email address will not be published.

Start typing and press Enter to search