How to delete nonempty directory?

How to delete nonempty directory?
Thanks

The directory has to be empty to use the rmdir command.. you can use rm yourdir/*; rmdir yourdir

Or you can use rm -r yourdir, but be careful. This is recursive, so all the files in yourdir will be deleted, then yourdir will be deleted, and if the directory yourdir was in is now empty, that will get deleted too. Read the rm man page for more info.

2 Likes

I'd suggest using rm -r ./yourdir from one dir level higher just so you're sure that deleting the correct directory. rm -r isn't very forgiving.

If you don't want it to ask you for confirmations you can use rm -rf ./yourdir.