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,873
Juan
  • 1,797
  • 1
    Are there any hidden files in there? Those start with a . and are not shown in most GUI file managers by default – s3lph Jan 15 '16 at 13:32
  • There is no any kind of files in this directory. I have the "Show hidden files" ON in thunar, and at the terminal session, with root privileges, nothing is diplayed. – Juan Jan 15 '16 at 18:07
  • The directory might have the immutable bit set. See http://binblog.info/2011/01/30/make-directory-immutable-on-linux/ – Elder Geek Jan 26 '16 at 19:44

2 Answers2

2

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,873
  • I did all the instructions you wrote and... Nothing!!! The system doesn't show me any file on the directory but it can not to remove it!!! It is a very rare behaviour, because I can erase any other directory with the commands you wrote!!! This HDD is a NTFS partition; all the directories and files come from a Windows system. Could it be some part of the reason? ??? – Juan Jan 15 '16 at 18:24
  • When I use "dir -a", the system shows me a "." (one single dot) and ".."(two dots). If Linux works the same as Windows on this point, those dots are just references to the parents directories. Or... Am I wrong? ??? – Juan Jan 15 '16 at 18:27
  • About "File not found" issue, it is so rare: when I ask the system a "dir -a" the system shows the files: "bt_Main_button2.bmp" "bt-Main_Manual.bmp" and "bt_Manual_Product2.bmp" BUT... When I ask it "sudo rm" and use the [Tab] key, I can only see the "bt_Ma" part of the names!!! What's wrong here? ??? – Juan Jan 15 '16 at 18:37
  • Okay, I think I can help you to track down your problem. Please edit your question and include the output of the following steps: cd to the directory that contains the directory you want to delete; run ls -la and ls -la <name of the dir you want to delete>; Then runrm andrm-r . Btw, as long as your working inside your home directory, you don't needsudo`. – Wayne_Yux Jan 15 '16 at 19:51
  • I added the information you asked from me. When I use rm or rm -r it doesn't work (system always says the same error mesage). – Juan Jan 16 '16 at 00:58
  • your issue may be caused by spaces in the directory name. Please run the following command: sudo rmdir "matrimonio de fiesta sara y luis hernan" (notice the " around the name). Does this work? If yes, I can add an explanation to my answer – Wayne_Yux Jan 16 '16 at 12:53
  • No. I tried it a lot of times and it didn't work. – Juan Jan 16 '16 at 17:23
  • what happens with rm -rf *? Normally, this should remove all files and directories in the directory you are currently in. – Wayne_Yux Jan 16 '16 at 17:55
  • rm -rf didn't work for me with this directory. I've tried with others directories and that command works! I created a "/Temp/test" directory and I put some text files on it, and rm -rf removed it as we'd expected! But... in this specific directory... Nothing! Originally, the "infamous" directory had a lot of pictures from a wedding. I uploaded all those pictures to facebook and I made a copy of them into an external HDD, then I erased them from the directory and I tried to remove it, But... Here, we are! – Juan Jan 16 '16 at 18:22
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,817