Unix & Linux: "cannot remove 'some_directory': Directory not empty" (3 Solutions!!)
Unix & Linux: "cannot remove 'some_directory': Directory not empty" The Question: I tried to delete some directory, but $ rm DE.aspx_files -r rm: cannot remove `DE.aspx_files': Directory not empty But listing its content returns none $ ls DE.aspx_files $ Added: Actually $ ls -la DE.aspx_files total 4 drwx------ 1 ting ting 4096 Sep 14 20:48 . drwx------ 1 ting ting 0 Sep 13 22:34 .. -rw------- 1 ting ting 0 Sep 13 22:34 .fuse_hidden0001d4bf00000006 When I try to rm .fuse_hidden0001d4bf00000006, it is deleted, but another new .fuse_hidden0001d4bf00000007 created. So I wonder what happened, and how to fix this problem? Note: it is a newly bought external portable HDD, and I just copy some files to it using a data recovery program. OS: Ubuntu 12.04 Thanks! Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful == This solution helped 17 people == **** Hidden Files **** You may have hidden files. You can find them with ls -la to make sure you're okay with really deleting them first. Then you can delete the files before running rm -r or rmdir as needed. **** Forcing the Recursive Delete **** You can also just do rm -rf to force the recursive deletion even if the target directory contains files. All the usual warnings apply, but it will get the job done regardless of what your directory contains--as long as you have permissions to delete the files and directories, of course. == This solution helped 64 people == Files of the form .fuse_hidden* are created by http://en.wikipedia.org/wiki/ Filesystem_in_Userspace filesystems when a file is deleted but still in use somewhere and must still have a directory entry. This is similar to .nfs* files on directories exported over NFS. Run df -T . to see the type of filesystem that's mounted on the current directory and its mount point. For an external hard disk, chances are that this is an NTFS filesystem mounted through the http://en.wikipedia.org/wiki/NTFS-3G driver, which is base on FUSE. The name is a fake name that the filesystem driver invents for a deleted file. You can't delete the file (or rather, if you create the file, it reappears under another name). You can't delete the directory either, since it isn't empty. You'll need to find what is using this file. The most likely cause of being in use is if it's open by some application. Run lsof /media/mount-point where /media/mount-point is the filesystem mount point and look for an open file in that directory. With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user Tim (https://unix.stackexchange.com/users/674), user Gilles 'SO- stop being evil' (https://unix.stackexchange.com/users/885), user DileepNimantha (https://unix.stackexchange.com/users/248894), user CodeGnome (https://unix.stackexchange.com/users/17673), and the Stack Exchange Network (http://unix.stackexchange.com/questions/48227). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.
Unix & Linux: "cannot remove 'some_directory': Directory not empty" The Question: I tried to delete some directory, but $ rm DE.aspx_files -r rm: cannot remove `DE.aspx_files': Directory not empty But listing its content returns none $ ls DE.aspx_files $ Added: Actually $ ls -la DE.aspx_files total 4 drwx------ 1 ting ting 4096 Sep 14 20:48 . drwx------ 1 ting ting 0 Sep 13 22:34 .. -rw------- 1 ting ting 0 Sep 13 22:34 .fuse_hidden0001d4bf00000006 When I try to rm .fuse_hidden0001d4bf00000006, it is deleted, but another new .fuse_hidden0001d4bf00000007 created. So I wonder what happened, and how to fix this problem? Note: it is a newly bought external portable HDD, and I just copy some files to it using a data recovery program. OS: Ubuntu 12.04 Thanks! Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful == This solution helped 17 people == **** Hidden Files **** You may have hidden files. You can find them with ls -la to make sure you're okay with really deleting them first. Then you can delete the files before running rm -r or rmdir as needed. **** Forcing the Recursive Delete **** You can also just do rm -rf to force the recursive deletion even if the target directory contains files. All the usual warnings apply, but it will get the job done regardless of what your directory contains--as long as you have permissions to delete the files and directories, of course. == This solution helped 64 people == Files of the form .fuse_hidden* are created by http://en.wikipedia.org/wiki/ Filesystem_in_Userspace filesystems when a file is deleted but still in use somewhere and must still have a directory entry. This is similar to .nfs* files on directories exported over NFS. Run df -T . to see the type of filesystem that's mounted on the current directory and its mount point. For an external hard disk, chances are that this is an NTFS filesystem mounted through the http://en.wikipedia.org/wiki/NTFS-3G driver, which is base on FUSE. The name is a fake name that the filesystem driver invents for a deleted file. You can't delete the file (or rather, if you create the file, it reappears under another name). You can't delete the directory either, since it isn't empty. You'll need to find what is using this file. The most likely cause of being in use is if it's open by some application. Run lsof /media/mount-point where /media/mount-point is the filesystem mount point and look for an open file in that directory. With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user Tim (https://unix.stackexchange.com/users/674), user Gilles 'SO- stop being evil' (https://unix.stackexchange.com/users/885), user DileepNimantha (https://unix.stackexchange.com/users/248894), user CodeGnome (https://unix.stackexchange.com/users/17673), and the Stack Exchange Network (http://unix.stackexchange.com/questions/48227). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.