This script searches for sidecar files of images for which the actual images no longer exist.
Features:
- Processes XMP, other sidecar files possible.
- Tested on macOS and Linux. It should also run on Windows if the Windows Subsystem for Linux is installed.
- Accelerated through parallelization.
- Does not delete automatically; you review the candidates for deletion.
- Basic Knowledge of using the shell on Linux or macOS is required.
- Optional: Git installation on your computer.
- Download the script.
- Make the script executable:
chmod +x photo-sidecar-cleaner.sh
.
Tip
The script creates temporary files. Therefore, install the script in its own folder, to keep your folder clean.
Note
- Create a backup of your data before running the script.
- Create test data. Run the script and check if the results meet your expectations.
- Identify a folder that may contain orphaned sidecar files.
- Copy the folder path.
- Open the shell.
- Change to the folder containing the script.
- Create the search command:
photo-sidecar-cleaner.sh <Folder> xmp
Tip
- You can also search for other sidecar files. Replace
xmp
with, for example,dop
to search for sidecar files from DxO PhotoLab. - Exclude folders: You can speed up the search if you want to ignore certain folders. On Synology NAS systems, for example, you can exclude
@eaDir
folders. Append@eaDir
to the search command.
- Execute the search.
Results:
The following files are created in the script's folder:
File | Remark |
---|---|
delete_commands.sh |
Sidecar files that can be deleted. |
found.txt |
Image files that were found. |
found_files_total.txt |
All sidecar files. |
Note
Each time the script executes, these files will be overwritten.
- Check the file
delete_commands.sh
(if orphaned sidecar files were found). - Review the entries. Check, for example, if only sidecar files are listed.
- Make the script executable:
chmod +x delete_commands.sh
. - Run the script:
./delete_commands.sh
.
Result: The sidecar files have been deleted.
Note
This procedure is only possible if you have configured Lightroom Classic to save metadata in XMP files. This is not the case by default. See Metadata and XMP (Adobe Help). As our scenario shows, it makes sense to enable the setting Automatically write changes into XMP
. If you store metadata in the Lightroom Classic catalog, you must search for the change manually:
Find missing photos (Adobe Help).
- Switch to Library mode.
- Expand the Folder panel.
- Right-click on a folder and select the command
Synchronize Folder
.
Note
This command does not synchronize with the cloud.
- Activate the option
Remove Missing Pictures
.
Result: The catalog is updated.
Unlike other image programs, DxO does not use a database. Therefore, an update is not necessary.
Note
If you work with projects, removing image files will cause inconsistencies in DxO PhotoLab's project database. In this case, only creating a new project can help.
Note
Capture One usually detects changes to cataloged content automatically.
- Switch to the Library tab.
- Right-click on a folder and select the command
Synchronize
. - Activate the option
Remove Missing Pictures
.
Result: The catalog is updated.
Typically, metadata such as tags or ratings of photos are stored not in the photo file itself but externally. This protects the image file. Most often, sidecar files have the extension XMP. These sidecar files differ from an image file only by the extension.
Moreover, there can also be other extensions. For example, the program DxO PhotoLab saves its processing steps in DOP files. There can also be other file types. Therefore, I wrote the script so that you can search for any type.
See also: Sidecar file (Wikipedia)
The cause is often an unthoughtful workflow, leading to an image ending up in different folders. Therefore, a good strategy for storing image files is worthwhile to avoid unwanted redundancies.
When we edit images with a program, the original image file usually remains unchanged. However, changes often occur to the sidecar files. With Lightroom Classic, an image does not even need to be changed for this to happen. If we export an unchanged image file, data about the export is saved in the sidecar file. If such an image is also located elsewhere, the image files do not differ, but the sidecar files do.
If we clean up our data structure, we can find and delete duplicate images with a duplicate search. Since the sidecar files differ, the duplicate search cannot help us here.
In my observation, DxO PhotoLab, Lightroom Classic, or Capture One notice when an image file is missing. This is considered an error that must be resolved manually. If hundreds of images have been removed through a duplicate search, the problem cannot be fixed in a reasonable amount of time. See, for example, Find missing photos (Adobe Help).
No, files are only deleted if you execute the file delete_commands.sh
created by the script. Therefore, you should check this file before you run it.