Sometimes we need delete a directory that is not empty and we get permission errors such as "Permission denied" or also "Directory not empty" when trying to do so because it is not empty and perhaps some of the directories or files it contains have special permissions that are the cause of the error. But it is possible to eliminate it easily with the minitutorial that we now offer you and make these messages not impediments to do so.
En a previous tutorial We saw how to be able to eliminate directories with quite extensive content, that is, directories with a considerable weight of several GB without affecting the performance of the system. And we achieved this thanks to ionice, a very practical tool that allows us to control the priority of certain transactions in the I / O system, as nice does with processes. Well, today we will focus on another simple action, but that may be giving some problem to the newest Linux users.
The steps to follow when we try to delete our directory that is not empty would be to try with:
But in that case we can receive the error message we were talking about. To do it correctly, you can try the following:
rm -rfv /mi-directorio
What we get with these rm options is a recursive deletion for the contents of the directory and also force deletion respectively. The -v is simply the verbose mode of the command to display more information on standard output.
In the event that we still get the permission error, because we will try to obtain privileges so that we no longer have problems when trying to delete it, you can do it with su, or more recommended with sudo:
sudo rm -rfv /mi-directorio
I hope it helped you with those stubborn directories that cannot be removed ...
6 comments, leave yours
Missing "rm" in:
sudo rm -rfv / my-directory
Thanks!!! My fault.
Thanks carnal, just that I needed, greetings
Thanks for the help, I already tried everything and I only needed -rfv only 4 characters
sudo rm -rfv my-directory
It worked like this for me, in Ubuntu 20.04, is it a problem?
You forgot to add something important, if a folder is not deleted with an rm -rfv foldername and the symbol ">" appears underneath, it is because it is not deleted like this, but with an rm -rfv "foldername" (this happens, when a folder has spaces in the name, so use quotes).
I hope it is useful to you. Greetings