0

I've been trying to erase (remove) a directory from one of my internal HDD and the system tells me that "The directory can not be removed because it is not an empty directory."

The issue is that the directory IS empty!

At least, I can not to see any inside it with Thunar file manager or from the Terminal with root privileges.

The directory where the directory I want to delete is, has this output to ls-la:

total 28

drwxrwxrwx 1 root root  4096 ene 15 10:01 .

drwxrwxrwx 1 root root 20480 ene 15 10:01 ..

drwxrwxrwx 1 root root  4096 ene 15 10:01 matrimonio de fiesta sara y luis hernan

And, the directory I want to delete, has this output:

total 8

drwxrwxrwx 1 root root 4096 ene 15 10:01 .

drwxrwxrwx 1 root root 4096 ene 15 10:01 ..

A similar case with another directory which has 3 files and, each time I was trying to remove them, the system tells me: "Files not found."

I was trying with sudo rm -r -f and... Nothing!

The same history each time I used it. What's wrong here?

Is there another, more powerful, command to remove directories and/or files?

Wayne_Yux
  • 4,942
Juan
  • 1,917

2 Answers2

3

You can remove empty directories with rmdir <directory> and non-empty directories with rm -r <directory>.


What causes you trouble, may be the following:
Consider this directory content:

$ tree -a
.
├── empty
├── non-empty
│   └── file.txt
└── non-empty-with-hidden-file
    └── .file.txt

We have an epty directory, on containing a file and one containing a hidden file. Now run rmdir *:

$ rmdir *
rmdir: failed to remove `non-empty': Directory not empty
rmdir: failed to remove `non-empty-with-hidden-file': Directory not empty
$ tree -a
.
├── non-empty
│   └── file.txt
└── non-empty-with-hidden-file
    └── .file.txt

As you can see, empty was removed and the other two caused error messages. Now you can run rm -r:

$ rm -r non-empty
$ tree -a
.
└── non-empty-with-hidden-file
    └── .file.txt

Your file not found error is probably not caused by rm, but by a typo in your filename or your directory path. You can avoid this by using the autocomplete function (Tab) instead of typing by hand.

Wayne_Yux
  • 4,942
0

Wayne's answer is correct, but if an error occurs you can add the '-f' switch to rm, "forcing" the removal:

sudo rm -rf "/path/to/the/directory"

Eduardo Cola
  • 5,876
  • 3
  • 20
  • 33