Mojave won't delete my empty directory

I have a directory which is definitely definitely empty, but Mojave says it isn't, and won't delete it.


Last week my MBP died. On Monday my new 2TB iMac 5K arrived, I put the MBP disk in a USB3 enclosure and used Migration Assistant to transfer the data (after it had updated the iMac to the latest High Sierra to match the MBP). All seemed well, and finished just as Mojave became available, so I updated the iMac to Mojave 10.14.


Whilst tidying up the next day, deleting a Lightroom 'Previews.lrcat' tree (for what that's worth), it failed to delete a directory named "C8E6".


Finder said the item was in use (which I doubted, and anyway lsof didn't find anything);

"rmdir" said "Directory not empty"; "rm -rf" said the same.


There doesn't seem to be anything in there:

$ ls -Rail C8E6/

total 0

786499 drwxr-xr-x 3 me staff 96 20 Jan 2016 .

12886106817 drwxrwxrwt 3 root wheel 96 28 Sep 19:19 ..


Contrast with this, which does seem to think it's empty:

$ rm -ri C8E6

examine files in directory C8E6? y

remove C8E6? y

rm: C8E6: Directory not empty


That link count of 3 on "." - which should be 2 on an empty directory - suggests either a subdirectory or corruption, and as you can see we're all outta subdirectories.


I know Time Machine makes hard links to directories, but I don't know how to investigate that.


I did a Disk Utility "First Aid", which was happy, and rebooted single user and did an fsck, which was also happy, remounted rw and tried to delete, but it wouldn't. I rebooted in safe mode too, for completeness, but I was still unable to delete.


I've moved the directory to Trash (which worked) and tried to empty it (which didn't); I tried the "really really empty Trash" meta-key combination, but that made no difference.


In case Apple were doing something clever with "ls" & "rmdir", I even made a C program to do opendir/readdir & rmdir, but they behaved as expected (i.e., showed only "." and "..", and failed to rmdir with errno 66 "Directory not empty".


Any suggestions?

The link count bothers me, not least because it doesn't seem to bother fsck.

iMac (Retina 5K, 27-inch, 2017), macOS Mojave (10.14), 2TB, Radeon Pro 580, 3.8GHz, 24GB

Posted on Sep 30, 2018 8:59 AM

Reply

Similar questions

5 replies

Sep 30, 2018 9:56 AM in response to aa599

The parent directory ".." is owned by root:wheel and has the sticky bit set on. On many UNIX operating systems, a file or folder with a sticky bit set cannot be removed. Also, are there any ACL or chflags {uchg, schg) set that may also be blocking removal of this folder?


ls -@RelO /path/to/parent of C8E6


You may have to use elevated privileges to strip that sticky bit, or change its ownership.


sudo chmod -t /path/to/parent folder of C8E6

Nov 12, 2018 10:38 AM in response to aa599

I have exactly the same issue on High Sierra 10.13.6: hardlink count 3 on an empty directory that cannot be deleted, even from the Terminal in Recovery mode. Tried to disable SIP. Tried to boot on another High Sierra, mount my main system. Tried to rename and move the folder. Ran DiskUtility. Deleted all TimeMachine local snapshots. Nothing worked so far :-( I believe there is some APFS corruption, but we have no repair utility (DiskWarrior is working on APFS support).

Sep 30, 2018 11:08 AM in response to VikingOSX

But I'm not trying to remove the parent directory (the ".." with the sticky bit set) - which, at the time of that ls, was /tmp.

I don't have any problems removing objects in /tmp before or since, so I suggest that's irrelevant.


I've since moved C8E6 to ~/.Trash (which is 700 and no extended attributes)


Apart from all that, I'd be surprised if a problem with permissions, ownerships, sticky bits, ACL, or attribute keys would produce a "Directory not empty" error - unless they affected removal of objects within the directory ... of which there are none!


But for completeness:


$ ls -@ROle

total 0

drwxr-xr-x 3 me staff - 96 20 Jan 2016 C8E6


./C8E6:

$


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mojave won't delete my empty directory

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.