MacOS – Moving files (manually in Finder, via terminal MV, or via script) appears to leave a ‘ghost’ file in search results that cannot be deleted

catalinafindermacossearch

Scenario:

  • I use plex with a DVR and torrents to download tv shows and the accompanying files.
    The DVR files save to DRIVE_1, and the permanent storage for PLEX is DRIVE_2.

Issue:

  • When the files are moved, it appears that many (some, not all) files are 'ghosted'. Essentially, the files that have been moved still 'appear' in the search results of smart folders, but they aren't real files. They cannot be edited, deleted, etc. I cannot seem to remove them from the search, even though they do not physically exist on the drive being searched.

Layout:

  • They are both physical drives.
  • DRIVE_1 is OSX Journaled, and DRIVE_2 is EX_FAT.
  • My script is an applescript 'app' that uses "do shell script" to run a series of BASH commands to mv the files that are relevant. They are also being renamed using "A Better Finder Rename" call out before the MV command.
  • I use MV, and not CP, because DRIVE_1 needs to be free for other files.

Process:

  • Either manually using (Command down) Drag and Drop, OR via the MV command in terminal in the script, the system will find the *.mp4/mkv/etc file types, rename them, and then MV them to the TV_Shows directory.
    Here is an example:

    do shell script "find /Volumes/DVD_Scratch/Downloads -iname '*.mp4' -exec open -a /Users/MYName/Documents/xHelper_Apps/DVDNameFix.app {} +;"

    do shell script "find /Volumes/DVD_Scratch/Downloads -iname '*.mp4' -size +90M -exec mv -v '{}' /Volumes/DVD_Music/TV_Shows/_Unsorted_TV/ \;"

As you can see, this basically finds all mp4s, sends them to the Renamer App, then 'qualifies' if they are over 90mb, and MVs those to a folder.

I think this is where the issue comes in. Some of those files, after the MV, the filenames in the original location are still showing as 'ghosts' in the system.

I can't explain it any other way, because:

  • They DO show up in a Smart Folder/Search
  • They do NOT show up in Terminal
  • They do NOT show up with a file path.

See in the image below. in the smart search, I am simply looking at 2 things: Location=DRIVE_1, and KIND=Movie.
You will note that "The Munsters" and "Smallville" are selected. The Munsters is a 'ghost' file, in that:

  • It has no file location (no "where" in the info)
  • It has no Edit or Read Access
  • I cannot drag it to the trash
  • I cannot CMD-Delete it
  • I cannot drag it to the terminal (it does nothing)

What I've Tried:

  • Rebuild Spotlight
  • Reindex via terminal (sudo mdutil -i on /)
  • sudo rm -rf /.Spotlight-V100 AND sudo rm -rf /.Spotlight-V200
  • Repairing Permissions from Disk Utility
  • Running Daily/Weekly/Monthly from Terminal
  • Running diskutil repairvolume /Volumes/MYVolume/
  • Recreated the search.folder
  • Deleted /Library/Caches for Finder
  • Deleted /FinderPreferences

What does work:
I know that if I reformat completely, this does go away; but that is not a regular solution; at least, it shouldn't be.

Looking for ideas on next steps, or at least the cause.

Image of Smart Search and Finder Get Info on Catalina

Best Answer

So, the solution is that the EXTERNAL drives, for whatever reason, were not re-indexing Spotlight.

I ran this command directly pointed to the DRIVE itself, and this cleared the results.

sudo mdutil -i on /Volumes/DRIVE_1

So, the takeaway is: Spotlight re-indexing (sudo mdutil -i on /) is only for the main HDD. Which, is weird, but that's what did it.