I'm having a tough time trying to reclaim some unused disk space on one of my macOS 10.13 partitions.

Thanks to GrandPerspective, I think I found out that every time I delete some items in Photos for Mac, in the case where they were inherited from iPhoto, what happens is that the hard link sitting in the Photo Library.photoslibrary folder is deleted, so resulting in an orphaned file being left over in the iPhoto Library.migratedphotolibrary folder.

So what I would need is to

  1. find all files with hard link count = 1 in the old iPhoto Library.migratedphotolibrary folder (the ones with link count = 2 need to stay there, as most likely they are hard-linked also in the new Photo Library.photoslibrary folder);
  2. delete them.

Some batch procedure executable from Terminal achieving both on the fly would be super. Even some initial hint would help me out a lot.

  • I'm sure you know better about your situation than me, but if you deleted the files with link count 2 in the old folder as well, wouldn't they still remain as files with link count 1 in the new library folder, and isn't that what you want? Jul 21 '19 at 13:58
  • Guess you are right! Just did not think about it :)
    – vastunghia
    Jul 21 '19 at 14:03

You are so close: You use find and rm.

 find «directory name» -links 1 -exec echo '{}' '+'

echo is not the correct command. After testing, change it to rm --.

  • 1
    Does MacOS' find have the --delete action? Saves a bit of possible headache with filename quoting. Jul 21 '19 at 13:50
  • @UlrichSchwarz Does it? There are no quoting issues with -exec rm {} + as far as I know, unless you're running tcsh.
    – Kusalananda
    Jul 21 '19 at 14:19
  • 1
    @UlrichSchwarz, it's -delete, and yes, Mac's find has it. Not that -exec rm {} + should have any quoting issues anyway (it doesn't run a shell)
    – ilkkachu
    Jul 21 '19 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.