Delete a non-empty directory when we get an error trying

Directory, icon

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:

rmdir /mi-directorio

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 ...


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

6 comments, leave yours

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Cristhian said

    Missing "rm" in:
    sudo rm -rfv / my-directory

    1.    Isaac PE said

      Thanks!!! My fault.
      Greetings.

  2.   Ismael said

    Thanks carnal, just that I needed, greetings

  3.   neiri said

    Thanks for the help, I already tried everything and I only needed -rfv only 4 characters

  4.   Dxniel said

    sudo rm -rfv my-directory
    It worked like this for me, in Ubuntu 20.04, is it a problem?

  5.   noobsaibot73 said

    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

bool (true)