Bash – Move Picture Based on Camera Type

| | | |

NOTE: This will typically only work on pictures that have been obtained from the camera that took the picture. (Social media services typically remove the needed information to get the EXIF info to determine the camera type.)

Prerequisite is to install exiftool (See https://exiftool.org for more installation help)

# macOS
brew install exiftool

# Debian, Ubuntu
sudo apt install -y exiftool

# RHEL, Rocky, CentOS, Fedora
sudo dnf install perl-Image-ExifTool

In this first block of code you will get the camera type listed for every picture that is in the current directory.

#!/bin/sh

find . -type f -name \*.jpg -o -name \*.jpeg -o -name \*.JPG -o -name \*.dng >picture_files.txt

while IFS="" read -r picture || [ -n "$picture" ]; do

	file=$(basename -- "$picture")
	extension="${file##*.}"
	filename="${file%.*}"

	camera=$(exiftool ${picture} | grep -i 'Camera Model Name' | cut -d ':' -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')

	echo "${file} - ${camera}"

done <picture_files.txt

This next block will actually move them into a specific directory for the camera type.

#!/bin/sh

find . -type f -name \*.jpg -o -name \*.jpeg -o -name \*.JPG -o -name \*.dng >picture_files.txt

while IFS="" read -r picture || [ -n "$picture" ]; do

	file=$(basename -- "$picture")
	extension="${file##*.}"
	filename="${file%.*}"

	camera=$(exiftool ${picture} | grep -i 'Camera Model Name' | cut -d ':' -f2 | sed 's/^[ \t]*//;s/[ \t]*$//')

	echo "${file} - ${camera}"

	mkdir -pv "${camera}"

	mv -vf ${picture} "${camera}"

done <picture_files.txt
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.