📄 picture-name-date-time | home

Rename Pictures Using Date and Time on Linux

guest@techdiy:~$

Automated Image Renamer with Original Creation Date & time

Script Description

This Bash script is a simple yet powerful automation tool that renames multiple image files in a folder by adding each file’s original creation date and time (from its EXIF metadata) to the filename. Instead of renaming photos manually, the script processes all images at once, making it easy to keep large photo collections organized and consistently labeled.

By pulling the actual date and time each picture was taken, the script ensures your filenames reflect the true capture moment — not when the file was copied or edited. This makes it especially useful for backing up, archiving, or sorting images chronologically, whether they come from phones, cameras, or different devices.

Although originally inspired by the needs of photographers, this script is designed for anyone who wants better photo organisation — from casual users managing family albums to professionals keeping structured backups.

Key features include

In short, this script saves time, removes the hassle of manual renaming, and helps you maintain a tidy, well-organized image library — automatically.

Requirements

need to install exiftool - find how to install it on your distro.

Here's the script

picture-name-date-time.sh:
#!/bin/bash

# Script extracts the original creation date/time from images..
# ..and appends to the file name. (adapt it to your needs)
# (Add your pictures' extension if not listed on the very first line of the code)
# Use it on multiple files in the folder at once.
# Requires `exiftool` (install with: sudo apt install perl-image-exiftool)
# For farther manipulation you can use next apps to achieve the final result:
# 1. `fdupes` (CLI) - to find and delete duplicated files before use this script
# 2. `GPRename` (GUI) - powerful tool w/ lot of options to rename multiple files
# NOTE: If you have error: "No DateTimeOriginal found.." - comment the line 19 and
# ..un-comment the next line below (20)!

for img in *.jpg *.jpeg *.png; do
    # Skip if no matching files
    [ -e "$img" ] || continue

    # Extract the original date/time (from EXIF)
    datetime=$(exiftool -d "%Y%m%d%H%M%S" -DateTimeOriginal -s3 "$img")
	#datetime=$(exiftool -d "%Y%m%d%H%M%S" -MediaCreateDate -s3 "$img")

    if [ -n "$datetime" ]; then
        # Get base name without extension
        base="${img%.*}"
        ext="${img##*.}"

        # Construct new filename
        newname="${base}_${datetime}.${ext}"

        # Rename file (avoid overwriting existing files)
        if [ -e "$newname" ]; then
            echo "Skipping $img → $newname already exists"
        else
            mv "$img" "$newname"
            echo "Renamed: $img → $newname"
        fi
    else
        echo "No DateTimeOriginal found for $img, skipping..."
    fi
done

	

👣 Make the file executable:

chmod +x picture-name-date-time.sh

👣 Copy it into the images' folder in case

👣 Run the script...

./picture-name-date-time.sh

💡 Important Notes:

Before using this script, make sure to back up your original image files. While the script is designed to rename files safely, unexpected issues (like interrupted processes or incorrect metadata) could still lead to unwanted results. Having a backup ensures your photos remain safe no matter what happens.

⚠️ Disclaimer:

This script is provided “as is”, without any warranty of any kind, either expressed or implied. The author assumes no responsibility for data loss, damage, or any other issues that may arise from using or modifying this script. Use it at your own discretion and risk.