This script sorts photos into folders organized by their Exif creation date.
Features:
- Does not move files automatically; you review the candidates for new organization.
- Allows for organizing photos into a new or existing folder.
- Organizes photos into year, month, and optionally day folders. Example:
- Year and month folders (
y-m
the pattern):/your-folder/Pictures/2024/03
. - Year, month, and day folders (
y-m-d
the pattern):/your-folder/Pictures/2024/03/26
.
- Year and month folders (
- Optional specification of file extensions for image types.
- Optional exclusion of folders.
- Also moves XMP and DOP Sidecar files.
- Excludes images and sidecar files that are already present in the target folder.
- Excludes images and sidecar files that are already listed as candidate for moving.
- Basic knowledge of using the shell on Linux or macOS is required.
exiftool
must be installed. See How do I installexiftool
.- Optional: Git installation on your computer.
- Download the script.
- Make the script executable:
chmod +x move-photos-by-date.sh
.
Tip
Run the script in its own folder to keep your folder structure clean.
Note
- Create a backup of your data before running the script.
- Test the script with a small set of photos to ensure it works as expected.
- Determine the source folder containing your photos.
- Determine the target folder where the photos will be organized.
- Open the shell.
- Change to the folder containing the script.
- Create the command to organize the photos:
./move-photos-by-date.sh -s <Sourcefolder> -t <Targetfolder> -p <Pattern> [-e <Excludedfolders>] [-f <FileExtensions>]
Tip
<Pattern>
must be eithery-m-d
ory-m
, depending on how you want to organize the photos.<Excludedfolders>
is a comma-separated list of folders you want to exclude.<FileExtensions>
is a comma-separated list of file extensions to consider (e.g.,jpg,png
).
- Execute the command.
Results:
The script creates two files in the folder from which it is run:
File | Remark |
---|---|
move.sh |
Commands to move the photos. |
cannot_move.txt |
List of files that cannot be moved. |
Note
These files are overwritten each time the script is run.
- Review the
move.sh
file to see the move commands. - Check the
cannot_move.txt
file for files that could not be processed. - Execute
./move.sh
to move the photos.
Result: The photos have been organized according to their Exif creation date.
After the Photos have ben organized in a new structure, it might happen, that orphaned files might exist in the old source folder. Examples, why this might happen:
- In the target folder sidecar files of the photo exists. These sidecar files are not overwritten by this script. Though the sidecar files remain in the source folder structure.
- In the source folder, some other file types exist.
If only a few folders exist in the source folder, you can manually check them with the file manager of your choice.
- Use the following command to search for the remaining files:
find /your/old/folder/ -type f | while read -r file; do echo "rm \"$file\""; done > rest.sh
Note
This command will not delete the files.
- Review the
rest.sh
file. Remove the lines with files, you don't want to delete. - Make the script executable:
chmod +x rest.sh
. - Execute
./rest.sh
to delete the files. - Optionally: Move other files to another place with the file manager of your choice.
- Remove the folder.
Result: The old folder no longer exists.
Tip
If you only want to clean up sidecar files, you can use my script Photo-Sidecar-Cleaner.
Exif data is metadata stored in photos that contain information such as the date of capture, camera settings, and possibly location. This script uses the capture date from the Exif data to organize photos.
See also: Exif (Wikipedia)
Typically, metadata such as tags or ratings of photos are stored not in the photo file itself but externally. This protects the photo file. Most often, sidecar files have the extension XMP. These sidecar files differ from a photo file only by the extension.
See also: Sidecar file (Wikipedia)
Files that cannot be moved either lack the required EXIF data, or there was a conflict (e.g., a file with the same name in the target folder). Check cannot_move.txt
for details.
Yes, but you need to install the Windows Subsystem for Linux and install exiftool
within that subsystem.
On most Linux distributions, you can install exiftool
via your package manager. On macOS, you can install exiftool
with Homebrew: brew install exiftool
.