I have this empty directory, but I keep getting the following error message:
Cannot remove test: Directory not emptyI know this question has been asked plenty of times but none of them helped.
I tried ls -la to make sure there were no hidden files, and there does not seem to be:
I tried sudo rmdir test as well as sudo rm -rf test, and I just do not know what is wrong.
I read it might be a problem with the file system, but I have no idea how I would go about fixing that.
716 Answers
I had the same problem on a external hard disk, I tried so many ways using command line, but I failed every time. That's what worked for me:
- Right click on folder
- Move to trash
- Empty trash
Yes, it's silly but it worked for me (I don't really know how and why, but the damned folder no longer exist)
9I have win 10 + ubuntu dual system installed. And both systems share the windows parititions.
Recently, i also ran into unable to delete empty folders in those partitions under ubuntu. I can't find out solution to solve it under linux.
However, after i switch to windows, and run
chkdskvia cmd for the target disk. Some errors checked out.
and then i run
chkdsk /Fto fix disk error.
After it finish, i am able to delete those folders now.
2You could delete it by typing sudo rm -rf {dir_name}. The directory might have been set to read-only permission. I hope the given command can delete the folder.
I had the same issue not able to remove directory as it is not empty.
This sequence of operations worked for me.
From command line first
sudo rmdir --ignore-fail-on-non-empty folder-name-to-be-deleted
The above command helps ubuntu ignore directory is not empty.
- Then just go to the folder and Shift + Del. That is all.
If the directory is part of a filesystem mounted with CIFS (aka samba), and it contains a file that is a broken symbolic link, then ls fails to mention that file. (I observe this bug on a CIFS client running 14.04.2 LTS, and a server running 12.04.5 LTS.)
So the directory is not empty, but (over CIFS) you have no way to see that. The file can only be seen, and thus can only be deleted, by a command running on the fileserver hosting that filesystem.
2If you are using btrfs, it is possibly an empty directory with a non-zero i_size. You can check whether this is the case with:
stat -c %s testThe i_size of an empty folder in btrfs should be zero. In my case, I got 6160 with ~/.config/chromium/Default.
The suggested solution is to unmount the filesystem, run btrfs check to confirm the issue and check for other problematic directories, and finally run btrfs check --repair to fix. This operation is risky, though, so it's a good idea to backup files first.
Source: Btrfs Problem FAQ
GUI solution
- Move or cut & paste the folder to trash folder
- empty the trash
it is done.
Command-line solution
sudo mv folder_error/ .local/share/Trashyou can clear with trash-cli: trash-empty or
sudo rm -fr ~/.local/share/Trash/* 1 try this command:
sudo lsof | grep deleted Check in the list if your directory is still in use. :D
If so, stop the service and you will be able delete the directory.
1This problem appears when those folders or files are not copied completely. It's Input/Output Error. I tried to delete with Shift+Del or through commands, but these did not work. I tried right click and "Move to Trash" and it worked.
I had the same issue on Ubuntu 16.04 and I fixed it by:
- emptying the trash folder
- rebooting
Opening and closing the file manager did no good—only rebooting worked.
Check if directory is not active for any running application before deleting. I was unable to delete a directory with same message, I found out the reason was that the directory was open in an node.js application. After closing/exiting the application I was able to delete the folder.
In my case, I had a separate command that ran concurrently and added files while the delete was ongoing; likely rm finished deleting everything it had planned to delete, then tried to delete the folder at the end, saw it had contents, and then threw an error saying 'yo, something is not right'.
(It had to do with running code in serial vs. accidentally in parallel for me.)
You may consider this if you're dealing with this problem.
1I ran into this issue and found that the solution was quite simple for me.
I had a Node server running that periodically accessed the files in the folder I was trying to remove. This caused several small meta files to constantly exist inside the folder. The purpose of these files is beyond me.
Even rm -rf folder/* would not remove these files permanently, despite showing the message removed folder/file.xyz.
I suspected the server, shut it down and removed the files and the folder without fail.
2Maybe the directory or a file in it has an immutable bit set?
root@lina:~# mkdir test
root@lina:~# chattr +i test
root@lina:~# rmdir test
rmdir: konnte 'test' nicht entfernen: Die Operation ist nicht erlaubt
root@lina:~# lsattr -d test
----i---------e---- test
root@lina:~# chattr -i test
root@lina:~# rmdir testthen you should remove the immutable bit with ''chattr -i'' first.
you may use rm command recursive flag i.e.
rm -r folder/
I solved a similar problem:
The actual error I got is:
find: cannot delete ‘/home/lucid/x/SecurityCameras/B-Yard’: Directory not emptyThe command I used was:
find /home/lucid/x/SecurityCameras/B-Yard -mtime +15 -deleteThe directory inside /home/lucid/x/SecurityCameras/B-Yard is 2021, which is put there by the camera.
Deleting OR renaming the directory to something else and then back to 2021 FIXED the problem. Renaming and back again for B-Yard didn't do anything.
So just renaming the offending directory to something else, and then back to the original name fixes the problem. No need to delete anything.