Why do I get “Directory not empty” when I try to remove an empty directory? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How to delete a non-empty directory in Terminal?How to remove a directory in www folderDoes anyone know of any alternatives to recuva for file recovery?Why am I not being able to tar /opt and move it to my USB location in Linuxhow do I compare values in bash?Unable to Remove DirectoryCan't delete empty directories with strange names/home/username/desktop not recognized: “No such file or directory”Why do I see empty but undeletable files in Google Drive?Making sudo not ask for password
Did any compiler fully use 80-bit floating point?
Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?
Twin's vs. Twins'
Random body shuffle every night—can we still function?
Is there any significance to the prison numbers of the Beagle Boys starting with 176-?
Does the transliteration of 'Dravidian' exist in Hindu scripture? Does 'Dravida' refer to a Geographical area or an ethnic group?
Order between one to one functions and their inverses
Did John Wesley plagiarize Matthew Henry...?
Sally's older brother
3D Masyu - A Die
An isoperimetric-type inequality inside a cube
Number of generators of subgroup
New Order #6: Easter Egg
Is the time—manner—place ordering of adverbials an oversimplification?
Why not use the yoke to control yaw, as well as pitch and roll?
How to make an animal which can only breed for a certain number of generations?
Can the Haste spell grant both a Beast Master ranger and their animal companion extra attacks?
Does the main washing effect of soap come from foam?
How does the body cool itself in a stillsuit?
Problem with display of presentation
Table formatting with tabularx?
Should man-made satellites feature an intelligent inverted "cow catcher"?
When to apply negative sign when number is squared
malloc in main() or malloc in another function: allocating memory for a struct and its members
Why do I get “Directory not empty” when I try to remove an empty directory?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How to delete a non-empty directory in Terminal?How to remove a directory in www folderDoes anyone know of any alternatives to recuva for file recovery?Why am I not being able to tar /opt and move it to my USB location in Linuxhow do I compare values in bash?Unable to Remove DirectoryCan't delete empty directories with strange names/home/username/desktop not recognized: “No such file or directory”Why do I see empty but undeletable files in Google Drive?Making sudo not ask for password
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have this empty directory, but I keep getting the following error message:
Cannot remove test: Directory not empty
I 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.
command-line files delete
|
show 2 more comments
I have this empty directory, but I keep getting the following error message:
Cannot remove test: Directory not empty
I 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.
command-line files delete
Trysudo fsck /
– ike
Dec 29 '14 at 4:38
2
Is it a normal directory or a mount point. If this is a mount point, it should be unmounted before deleting. If it is a normal directory, sometime there might be some open handles cause this problem. Reboot your machine once and try to delete it.
– vembutech
Dec 29 '14 at 5:12
@rbrick Doestest
is your login user's name? what is the output ofecho $USER
? and whatecho $HOME
?
– αғsнιη
Dec 29 '14 at 11:52
1
I am confused, why does the user not have execute permissions on the directory, but group does?
– Julian Stirling
Aug 3 '15 at 4:45
2
possible duplicate of How to delete a non-empty directory in Terminal?
– Radu Rădeanu
Aug 27 '15 at 14:57
|
show 2 more comments
I have this empty directory, but I keep getting the following error message:
Cannot remove test: Directory not empty
I 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.
command-line files delete
I have this empty directory, but I keep getting the following error message:
Cannot remove test: Directory not empty
I 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.
command-line files delete
command-line files delete
edited Jan 16 '15 at 7:53
αғsнιη
25.1k23100162
25.1k23100162
asked Dec 29 '14 at 4:34
rbrickrbrick
178125
178125
Trysudo fsck /
– ike
Dec 29 '14 at 4:38
2
Is it a normal directory or a mount point. If this is a mount point, it should be unmounted before deleting. If it is a normal directory, sometime there might be some open handles cause this problem. Reboot your machine once and try to delete it.
– vembutech
Dec 29 '14 at 5:12
@rbrick Doestest
is your login user's name? what is the output ofecho $USER
? and whatecho $HOME
?
– αғsнιη
Dec 29 '14 at 11:52
1
I am confused, why does the user not have execute permissions on the directory, but group does?
– Julian Stirling
Aug 3 '15 at 4:45
2
possible duplicate of How to delete a non-empty directory in Terminal?
– Radu Rădeanu
Aug 27 '15 at 14:57
|
show 2 more comments
Trysudo fsck /
– ike
Dec 29 '14 at 4:38
2
Is it a normal directory or a mount point. If this is a mount point, it should be unmounted before deleting. If it is a normal directory, sometime there might be some open handles cause this problem. Reboot your machine once and try to delete it.
– vembutech
Dec 29 '14 at 5:12
@rbrick Doestest
is your login user's name? what is the output ofecho $USER
? and whatecho $HOME
?
– αғsнιη
Dec 29 '14 at 11:52
1
I am confused, why does the user not have execute permissions on the directory, but group does?
– Julian Stirling
Aug 3 '15 at 4:45
2
possible duplicate of How to delete a non-empty directory in Terminal?
– Radu Rădeanu
Aug 27 '15 at 14:57
Try
sudo fsck /
– ike
Dec 29 '14 at 4:38
Try
sudo fsck /
– ike
Dec 29 '14 at 4:38
2
2
Is it a normal directory or a mount point. If this is a mount point, it should be unmounted before deleting. If it is a normal directory, sometime there might be some open handles cause this problem. Reboot your machine once and try to delete it.
– vembutech
Dec 29 '14 at 5:12
Is it a normal directory or a mount point. If this is a mount point, it should be unmounted before deleting. If it is a normal directory, sometime there might be some open handles cause this problem. Reboot your machine once and try to delete it.
– vembutech
Dec 29 '14 at 5:12
@rbrick Does
test
is your login user's name? what is the output of echo $USER
? and what echo $HOME
?– αғsнιη
Dec 29 '14 at 11:52
@rbrick Does
test
is your login user's name? what is the output of echo $USER
? and what echo $HOME
?– αғsнιη
Dec 29 '14 at 11:52
1
1
I am confused, why does the user not have execute permissions on the directory, but group does?
– Julian Stirling
Aug 3 '15 at 4:45
I am confused, why does the user not have execute permissions on the directory, but group does?
– Julian Stirling
Aug 3 '15 at 4:45
2
2
possible duplicate of How to delete a non-empty directory in Terminal?
– Radu Rădeanu
Aug 27 '15 at 14:57
possible duplicate of How to delete a non-empty directory in Terminal?
– Radu Rădeanu
Aug 27 '15 at 14:57
|
show 2 more comments
11 Answers
11
active
oldest
votes
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)
I got the same issue and your answer works. Not quite sure what the silly thing happened, and why "-rf" failed to remove an non-empty folder.
– artm
Jun 12 '17 at 7:50
2
What just happened here? Why did it work?
– Sahil Arora
Feb 8 '18 at 20:42
What happened? Honestly, i don't know. Maybe, the folder's file was corrupted for some reason: a flag like "is-empty" or the file counter like "how-many-file-inside" has been setted to an erroneous value. Sometimes, errors like this could be caused by damages on the hard disk. Why did it work? I don't know how commands are implemented (think about C), but I guess they check those flags and counters before acting (i mean, if file counter >0 then "error: directory not empty" and abort), while emptying the trash directly remove the folder and all its file and subfolder without any kind of check.
– Marco Ottina
May 28 '18 at 10:58
Maybe, deleting a folder through command line requires some conditions, like the emptiness of the folder, (because removing the folder's node from file system removes only that single linknode and requires the folder to be empty so no other file-node would be "forgot" through the file system due to losing the intermediate link to them, represented by the folder) .. and deleting a folder through right click -> delete or emptying the trash removes the folder AND all file and subfolders recursively, not caring of flags, counters and stuffs like that (so, no checks are performed)
– Marco Ottina
May 28 '18 at 11:06
1
In my case, the subdirectory in question happened to be in a folder that was shared from my Mac to a linux VM, and I was trying to delete the folder from the linux VM side. It seems that the Mac side was holding onto some folders. Doing therm -rf
from the Mac side worked.
– MindJuice
Jun 7 '18 at 13:38
|
show 3 more comments
You 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 getDirectory not empty
anyway. It seems strange, so I recorded my screen to prove.
– naXa
Mar 14 at 22:24
That command in the answer works even if directory has contents and also with subdirectories.
– Wolverine
Mar 15 at 15:37
don't believe me just watch :D drive.google.com/open?id=1UEYVa4UT6df7xucrq-lO82xjk3afHHzA
– naXa
Mar 15 at 15:48
this strange behaviour was caused by errors in NTFS partition. solved withchkdsk /F
.
– naXa
Mar 15 at 15:50
add a comment |
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.
add a comment |
I 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
chkdsk
via cmd
for the target disk. Some errors checked out.
and then i run
chkdsk /F
to fix disk error.
After it finish, i am able to delete those folders now.
1
This method works for me. I think it is also important to note that the shared partition(s) is NTFS formatted and that it is probably corrupted.
– krismath
Jul 19 '18 at 9:25
add a comment |
If 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 test
The 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
add a comment |
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/Trash
you can clear with trash-cli: trash-empty
or
sudo rm -fr ~/.local/share/Trash/*
I think the command line solution here is actually a general solution. Move the empty folder to another location, and remove it once it's moved. E.g., something like thismkdir a ; mv test a/ ; rm -rf a/test ; rm -rf a
. An approach like that worked for me (although I have no idea why it would), and I didn't need root access.
– Jake Fisher
Jul 20 '18 at 21:57
add a comment |
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.
add a comment |
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.
add a comment |
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.
Obviously the directory won't show up in the list of open, deleted file descriptors if it can't be deleted. ;-]
– David Foerster
Jul 18 '17 at 13:18
add a comment |
This 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.
add a comment |
On my mac machine, I just used the command rm -Rf (capital R.) And viola!
New contributor
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f566474%2fwhy-do-i-get-directory-not-empty-when-i-try-to-remove-an-empty-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
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)
I got the same issue and your answer works. Not quite sure what the silly thing happened, and why "-rf" failed to remove an non-empty folder.
– artm
Jun 12 '17 at 7:50
2
What just happened here? Why did it work?
– Sahil Arora
Feb 8 '18 at 20:42
What happened? Honestly, i don't know. Maybe, the folder's file was corrupted for some reason: a flag like "is-empty" or the file counter like "how-many-file-inside" has been setted to an erroneous value. Sometimes, errors like this could be caused by damages on the hard disk. Why did it work? I don't know how commands are implemented (think about C), but I guess they check those flags and counters before acting (i mean, if file counter >0 then "error: directory not empty" and abort), while emptying the trash directly remove the folder and all its file and subfolder without any kind of check.
– Marco Ottina
May 28 '18 at 10:58
Maybe, deleting a folder through command line requires some conditions, like the emptiness of the folder, (because removing the folder's node from file system removes only that single linknode and requires the folder to be empty so no other file-node would be "forgot" through the file system due to losing the intermediate link to them, represented by the folder) .. and deleting a folder through right click -> delete or emptying the trash removes the folder AND all file and subfolders recursively, not caring of flags, counters and stuffs like that (so, no checks are performed)
– Marco Ottina
May 28 '18 at 11:06
1
In my case, the subdirectory in question happened to be in a folder that was shared from my Mac to a linux VM, and I was trying to delete the folder from the linux VM side. It seems that the Mac side was holding onto some folders. Doing therm -rf
from the Mac side worked.
– MindJuice
Jun 7 '18 at 13:38
|
show 3 more comments
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)
I got the same issue and your answer works. Not quite sure what the silly thing happened, and why "-rf" failed to remove an non-empty folder.
– artm
Jun 12 '17 at 7:50
2
What just happened here? Why did it work?
– Sahil Arora
Feb 8 '18 at 20:42
What happened? Honestly, i don't know. Maybe, the folder's file was corrupted for some reason: a flag like "is-empty" or the file counter like "how-many-file-inside" has been setted to an erroneous value. Sometimes, errors like this could be caused by damages on the hard disk. Why did it work? I don't know how commands are implemented (think about C), but I guess they check those flags and counters before acting (i mean, if file counter >0 then "error: directory not empty" and abort), while emptying the trash directly remove the folder and all its file and subfolder without any kind of check.
– Marco Ottina
May 28 '18 at 10:58
Maybe, deleting a folder through command line requires some conditions, like the emptiness of the folder, (because removing the folder's node from file system removes only that single linknode and requires the folder to be empty so no other file-node would be "forgot" through the file system due to losing the intermediate link to them, represented by the folder) .. and deleting a folder through right click -> delete or emptying the trash removes the folder AND all file and subfolders recursively, not caring of flags, counters and stuffs like that (so, no checks are performed)
– Marco Ottina
May 28 '18 at 11:06
1
In my case, the subdirectory in question happened to be in a folder that was shared from my Mac to a linux VM, and I was trying to delete the folder from the linux VM side. It seems that the Mac side was holding onto some folders. Doing therm -rf
from the Mac side worked.
– MindJuice
Jun 7 '18 at 13:38
|
show 3 more comments
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)
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)
edited Jul 18 '17 at 13:17
David Foerster
28.7k1367113
28.7k1367113
answered Feb 19 '16 at 10:13
Marco OttinaMarco Ottina
45643
45643
I got the same issue and your answer works. Not quite sure what the silly thing happened, and why "-rf" failed to remove an non-empty folder.
– artm
Jun 12 '17 at 7:50
2
What just happened here? Why did it work?
– Sahil Arora
Feb 8 '18 at 20:42
What happened? Honestly, i don't know. Maybe, the folder's file was corrupted for some reason: a flag like "is-empty" or the file counter like "how-many-file-inside" has been setted to an erroneous value. Sometimes, errors like this could be caused by damages on the hard disk. Why did it work? I don't know how commands are implemented (think about C), but I guess they check those flags and counters before acting (i mean, if file counter >0 then "error: directory not empty" and abort), while emptying the trash directly remove the folder and all its file and subfolder without any kind of check.
– Marco Ottina
May 28 '18 at 10:58
Maybe, deleting a folder through command line requires some conditions, like the emptiness of the folder, (because removing the folder's node from file system removes only that single linknode and requires the folder to be empty so no other file-node would be "forgot" through the file system due to losing the intermediate link to them, represented by the folder) .. and deleting a folder through right click -> delete or emptying the trash removes the folder AND all file and subfolders recursively, not caring of flags, counters and stuffs like that (so, no checks are performed)
– Marco Ottina
May 28 '18 at 11:06
1
In my case, the subdirectory in question happened to be in a folder that was shared from my Mac to a linux VM, and I was trying to delete the folder from the linux VM side. It seems that the Mac side was holding onto some folders. Doing therm -rf
from the Mac side worked.
– MindJuice
Jun 7 '18 at 13:38
|
show 3 more comments
I got the same issue and your answer works. Not quite sure what the silly thing happened, and why "-rf" failed to remove an non-empty folder.
– artm
Jun 12 '17 at 7:50
2
What just happened here? Why did it work?
– Sahil Arora
Feb 8 '18 at 20:42
What happened? Honestly, i don't know. Maybe, the folder's file was corrupted for some reason: a flag like "is-empty" or the file counter like "how-many-file-inside" has been setted to an erroneous value. Sometimes, errors like this could be caused by damages on the hard disk. Why did it work? I don't know how commands are implemented (think about C), but I guess they check those flags and counters before acting (i mean, if file counter >0 then "error: directory not empty" and abort), while emptying the trash directly remove the folder and all its file and subfolder without any kind of check.
– Marco Ottina
May 28 '18 at 10:58
Maybe, deleting a folder through command line requires some conditions, like the emptiness of the folder, (because removing the folder's node from file system removes only that single linknode and requires the folder to be empty so no other file-node would be "forgot" through the file system due to losing the intermediate link to them, represented by the folder) .. and deleting a folder through right click -> delete or emptying the trash removes the folder AND all file and subfolders recursively, not caring of flags, counters and stuffs like that (so, no checks are performed)
– Marco Ottina
May 28 '18 at 11:06
1
In my case, the subdirectory in question happened to be in a folder that was shared from my Mac to a linux VM, and I was trying to delete the folder from the linux VM side. It seems that the Mac side was holding onto some folders. Doing therm -rf
from the Mac side worked.
– MindJuice
Jun 7 '18 at 13:38
I got the same issue and your answer works. Not quite sure what the silly thing happened, and why "-rf" failed to remove an non-empty folder.
– artm
Jun 12 '17 at 7:50
I got the same issue and your answer works. Not quite sure what the silly thing happened, and why "-rf" failed to remove an non-empty folder.
– artm
Jun 12 '17 at 7:50
2
2
What just happened here? Why did it work?
– Sahil Arora
Feb 8 '18 at 20:42
What just happened here? Why did it work?
– Sahil Arora
Feb 8 '18 at 20:42
What happened? Honestly, i don't know. Maybe, the folder's file was corrupted for some reason: a flag like "is-empty" or the file counter like "how-many-file-inside" has been setted to an erroneous value. Sometimes, errors like this could be caused by damages on the hard disk. Why did it work? I don't know how commands are implemented (think about C), but I guess they check those flags and counters before acting (i mean, if file counter >0 then "error: directory not empty" and abort), while emptying the trash directly remove the folder and all its file and subfolder without any kind of check.
– Marco Ottina
May 28 '18 at 10:58
What happened? Honestly, i don't know. Maybe, the folder's file was corrupted for some reason: a flag like "is-empty" or the file counter like "how-many-file-inside" has been setted to an erroneous value. Sometimes, errors like this could be caused by damages on the hard disk. Why did it work? I don't know how commands are implemented (think about C), but I guess they check those flags and counters before acting (i mean, if file counter >0 then "error: directory not empty" and abort), while emptying the trash directly remove the folder and all its file and subfolder without any kind of check.
– Marco Ottina
May 28 '18 at 10:58
Maybe, deleting a folder through command line requires some conditions, like the emptiness of the folder, (because removing the folder's node from file system removes only that single linknode and requires the folder to be empty so no other file-node would be "forgot" through the file system due to losing the intermediate link to them, represented by the folder) .. and deleting a folder through right click -> delete or emptying the trash removes the folder AND all file and subfolders recursively, not caring of flags, counters and stuffs like that (so, no checks are performed)
– Marco Ottina
May 28 '18 at 11:06
Maybe, deleting a folder through command line requires some conditions, like the emptiness of the folder, (because removing the folder's node from file system removes only that single linknode and requires the folder to be empty so no other file-node would be "forgot" through the file system due to losing the intermediate link to them, represented by the folder) .. and deleting a folder through right click -> delete or emptying the trash removes the folder AND all file and subfolders recursively, not caring of flags, counters and stuffs like that (so, no checks are performed)
– Marco Ottina
May 28 '18 at 11:06
1
1
In my case, the subdirectory in question happened to be in a folder that was shared from my Mac to a linux VM, and I was trying to delete the folder from the linux VM side. It seems that the Mac side was holding onto some folders. Doing the
rm -rf
from the Mac side worked.– MindJuice
Jun 7 '18 at 13:38
In my case, the subdirectory in question happened to be in a folder that was shared from my Mac to a linux VM, and I was trying to delete the folder from the linux VM side. It seems that the Mac side was holding onto some folders. Doing the
rm -rf
from the Mac side worked.– MindJuice
Jun 7 '18 at 13:38
|
show 3 more comments
You 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 getDirectory not empty
anyway. It seems strange, so I recorded my screen to prove.
– naXa
Mar 14 at 22:24
That command in the answer works even if directory has contents and also with subdirectories.
– Wolverine
Mar 15 at 15:37
don't believe me just watch :D drive.google.com/open?id=1UEYVa4UT6df7xucrq-lO82xjk3afHHzA
– naXa
Mar 15 at 15:48
this strange behaviour was caused by errors in NTFS partition. solved withchkdsk /F
.
– naXa
Mar 15 at 15:50
add a comment |
You 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 getDirectory not empty
anyway. It seems strange, so I recorded my screen to prove.
– naXa
Mar 14 at 22:24
That command in the answer works even if directory has contents and also with subdirectories.
– Wolverine
Mar 15 at 15:37
don't believe me just watch :D drive.google.com/open?id=1UEYVa4UT6df7xucrq-lO82xjk3afHHzA
– naXa
Mar 15 at 15:48
this strange behaviour was caused by errors in NTFS partition. solved withchkdsk /F
.
– naXa
Mar 15 at 15:50
add a comment |
You 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.
You 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.
answered Dec 29 '14 at 23:32
WolverineWolverine
629413
629413
I getDirectory not empty
anyway. It seems strange, so I recorded my screen to prove.
– naXa
Mar 14 at 22:24
That command in the answer works even if directory has contents and also with subdirectories.
– Wolverine
Mar 15 at 15:37
don't believe me just watch :D drive.google.com/open?id=1UEYVa4UT6df7xucrq-lO82xjk3afHHzA
– naXa
Mar 15 at 15:48
this strange behaviour was caused by errors in NTFS partition. solved withchkdsk /F
.
– naXa
Mar 15 at 15:50
add a comment |
I getDirectory not empty
anyway. It seems strange, so I recorded my screen to prove.
– naXa
Mar 14 at 22:24
That command in the answer works even if directory has contents and also with subdirectories.
– Wolverine
Mar 15 at 15:37
don't believe me just watch :D drive.google.com/open?id=1UEYVa4UT6df7xucrq-lO82xjk3afHHzA
– naXa
Mar 15 at 15:48
this strange behaviour was caused by errors in NTFS partition. solved withchkdsk /F
.
– naXa
Mar 15 at 15:50
I get
Directory not empty
anyway. It seems strange, so I recorded my screen to prove.– naXa
Mar 14 at 22:24
I get
Directory not empty
anyway. It seems strange, so I recorded my screen to prove.– naXa
Mar 14 at 22:24
That command in the answer works even if directory has contents and also with subdirectories.
– Wolverine
Mar 15 at 15:37
That command in the answer works even if directory has contents and also with subdirectories.
– Wolverine
Mar 15 at 15:37
don't believe me just watch :D drive.google.com/open?id=1UEYVa4UT6df7xucrq-lO82xjk3afHHzA
– naXa
Mar 15 at 15:48
don't believe me just watch :D drive.google.com/open?id=1UEYVa4UT6df7xucrq-lO82xjk3afHHzA
– naXa
Mar 15 at 15:48
this strange behaviour was caused by errors in NTFS partition. solved with
chkdsk /F
.– naXa
Mar 15 at 15:50
this strange behaviour was caused by errors in NTFS partition. solved with
chkdsk /F
.– naXa
Mar 15 at 15:50
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Apr 15 '17 at 7:12
Anwar
57.6k22149257
57.6k22149257
answered Apr 15 '17 at 3:58
AmitAmit
412
412
add a comment |
add a comment |
I 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
chkdsk
via cmd
for the target disk. Some errors checked out.
and then i run
chkdsk /F
to fix disk error.
After it finish, i am able to delete those folders now.
1
This method works for me. I think it is also important to note that the shared partition(s) is NTFS formatted and that it is probably corrupted.
– krismath
Jul 19 '18 at 9:25
add a comment |
I 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
chkdsk
via cmd
for the target disk. Some errors checked out.
and then i run
chkdsk /F
to fix disk error.
After it finish, i am able to delete those folders now.
1
This method works for me. I think it is also important to note that the shared partition(s) is NTFS formatted and that it is probably corrupted.
– krismath
Jul 19 '18 at 9:25
add a comment |
I 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
chkdsk
via cmd
for the target disk. Some errors checked out.
and then i run
chkdsk /F
to fix disk error.
After it finish, i am able to delete those folders now.
I 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
chkdsk
via cmd
for the target disk. Some errors checked out.
and then i run
chkdsk /F
to fix disk error.
After it finish, i am able to delete those folders now.
answered Jul 12 '17 at 2:31
e-cloude-cloud
1507
1507
1
This method works for me. I think it is also important to note that the shared partition(s) is NTFS formatted and that it is probably corrupted.
– krismath
Jul 19 '18 at 9:25
add a comment |
1
This method works for me. I think it is also important to note that the shared partition(s) is NTFS formatted and that it is probably corrupted.
– krismath
Jul 19 '18 at 9:25
1
1
This method works for me. I think it is also important to note that the shared partition(s) is NTFS formatted and that it is probably corrupted.
– krismath
Jul 19 '18 at 9:25
This method works for me. I think it is also important to note that the shared partition(s) is NTFS formatted and that it is probably corrupted.
– krismath
Jul 19 '18 at 9:25
add a comment |
If 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 test
The 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
add a comment |
If 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 test
The 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
add a comment |
If 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 test
The 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
If 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 test
The 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
edited Apr 15 '17 at 6:00
Zanna
51.5k13141244
51.5k13141244
answered Feb 14 '16 at 9:29
wzhdwzhd
965
965
add a comment |
add a comment |
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/Trash
you can clear with trash-cli: trash-empty
or
sudo rm -fr ~/.local/share/Trash/*
I think the command line solution here is actually a general solution. Move the empty folder to another location, and remove it once it's moved. E.g., something like thismkdir a ; mv test a/ ; rm -rf a/test ; rm -rf a
. An approach like that worked for me (although I have no idea why it would), and I didn't need root access.
– Jake Fisher
Jul 20 '18 at 21:57
add a comment |
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/Trash
you can clear with trash-cli: trash-empty
or
sudo rm -fr ~/.local/share/Trash/*
I think the command line solution here is actually a general solution. Move the empty folder to another location, and remove it once it's moved. E.g., something like thismkdir a ; mv test a/ ; rm -rf a/test ; rm -rf a
. An approach like that worked for me (although I have no idea why it would), and I didn't need root access.
– Jake Fisher
Jul 20 '18 at 21:57
add a comment |
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/Trash
you can clear with trash-cli: trash-empty
or
sudo rm -fr ~/.local/share/Trash/*
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/Trash
you can clear with trash-cli: trash-empty
or
sudo rm -fr ~/.local/share/Trash/*
edited Jul 18 '17 at 13:23
David Foerster
28.7k1367113
28.7k1367113
answered Jul 18 '17 at 13:09
Kadir Y.Kadir Y.
315
315
I think the command line solution here is actually a general solution. Move the empty folder to another location, and remove it once it's moved. E.g., something like thismkdir a ; mv test a/ ; rm -rf a/test ; rm -rf a
. An approach like that worked for me (although I have no idea why it would), and I didn't need root access.
– Jake Fisher
Jul 20 '18 at 21:57
add a comment |
I think the command line solution here is actually a general solution. Move the empty folder to another location, and remove it once it's moved. E.g., something like thismkdir a ; mv test a/ ; rm -rf a/test ; rm -rf a
. An approach like that worked for me (although I have no idea why it would), and I didn't need root access.
– Jake Fisher
Jul 20 '18 at 21:57
I think the command line solution here is actually a general solution. Move the empty folder to another location, and remove it once it's moved. E.g., something like this
mkdir a ; mv test a/ ; rm -rf a/test ; rm -rf a
. An approach like that worked for me (although I have no idea why it would), and I didn't need root access.– Jake Fisher
Jul 20 '18 at 21:57
I think the command line solution here is actually a general solution. Move the empty folder to another location, and remove it once it's moved. E.g., something like this
mkdir a ; mv test a/ ; rm -rf a/test ; rm -rf a
. An approach like that worked for me (although I have no idea why it would), and I didn't need root access.– Jake Fisher
Jul 20 '18 at 21:57
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jun 19 '15 at 20:10
Camille GoudeseuneCamille Goudeseune
1669
1669
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Aug 3 '16 at 1:30
answered Aug 2 '16 at 21:20
daledale
112
112
add a comment |
add a comment |
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.
Obviously the directory won't show up in the list of open, deleted file descriptors if it can't be deleted. ;-]
– David Foerster
Jul 18 '17 at 13:18
add a comment |
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.
Obviously the directory won't show up in the list of open, deleted file descriptors if it can't be deleted. ;-]
– David Foerster
Jul 18 '17 at 13:18
add a comment |
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.
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.
edited Jan 1 '15 at 21:27
Eric Carvalho
42.6k17118148
42.6k17118148
answered Dec 29 '14 at 10:49
ashwin2011ashwin2011
294
294
Obviously the directory won't show up in the list of open, deleted file descriptors if it can't be deleted. ;-]
– David Foerster
Jul 18 '17 at 13:18
add a comment |
Obviously the directory won't show up in the list of open, deleted file descriptors if it can't be deleted. ;-]
– David Foerster
Jul 18 '17 at 13:18
Obviously the directory won't show up in the list of open, deleted file descriptors if it can't be deleted. ;-]
– David Foerster
Jul 18 '17 at 13:18
Obviously the directory won't show up in the list of open, deleted file descriptors if it can't be deleted. ;-]
– David Foerster
Jul 18 '17 at 13:18
add a comment |
This 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.
add a comment |
This 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.
add a comment |
This 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.
This 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.
edited Apr 9 '16 at 7:38
techraf
2,78592035
2,78592035
answered Apr 9 '16 at 4:28
lhodenizlhodeniz
53
53
add a comment |
add a comment |
On my mac machine, I just used the command rm -Rf (capital R.) And viola!
New contributor
add a comment |
On my mac machine, I just used the command rm -Rf (capital R.) And viola!
New contributor
add a comment |
On my mac machine, I just used the command rm -Rf (capital R.) And viola!
New contributor
On my mac machine, I just used the command rm -Rf (capital R.) And viola!
New contributor
New contributor
answered 28 mins ago
Dude803Dude803
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f566474%2fwhy-do-i-get-directory-not-empty-when-i-try-to-remove-an-empty-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try
sudo fsck /
– ike
Dec 29 '14 at 4:38
2
Is it a normal directory or a mount point. If this is a mount point, it should be unmounted before deleting. If it is a normal directory, sometime there might be some open handles cause this problem. Reboot your machine once and try to delete it.
– vembutech
Dec 29 '14 at 5:12
@rbrick Does
test
is your login user's name? what is the output ofecho $USER
? and whatecho $HOME
?– αғsнιη
Dec 29 '14 at 11:52
1
I am confused, why does the user not have execute permissions on the directory, but group does?
– Julian Stirling
Aug 3 '15 at 4:45
2
possible duplicate of How to delete a non-empty directory in Terminal?
– Radu Rădeanu
Aug 27 '15 at 14:57