Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Bash – Rename Picture

Posted on November 15, 2022August 17, 2024 By David Kittell

for f in *.HEIC; do
    mv -v "$f" "${f%.HEIC}.heic"
done

# 1
set -eu -o pipefail


# 2
count=$(find . -depth 1 -name "*.heic" | wc -l | sed 's/[[:space:]]*//')
echo "converting $count files .heic files to .jpg"

# 3
magick mogrify -monitor -format jpg *.heic

# 4
echo "Remove .heic files? [y/n]"
read remove

# 5
if [[ "$remove" == "y" ]]; then
  find . -depth 1 -name "*.heic" -delete
fi


for f in *.JPG; do
    mv -v "$f" "${f%.JPG}.jpg"
done

for f in *.AVI; do
    mv -v "$f" "${f%.AVI}.avi"
done

for f in *.MP4; do
    mv -v "$f" "${f%.MP4}.mp4"
done

for f in *.MOV; do
    mv -v "$f" "${f%.MOV}.mov"
done

for f in *.HEIC; do
    mv -v "$f" "${f%.HEIC}.heic"
done

set -eu -o pipefail
count=$(find . -depth 1 -name "*.heic" | wc -l | sed 's/[[:space:]]*//')
echo "converting $count files .heic files to .jpg"
magick mogrify -monitor -format jpg *.heic
find . -depth 1 -name "*.heic" -delete

# Add 12 hours to the picture's EXIF info
# exiftool "-AllDates+=0:0:0 12:0:0" -verbose *.jpg

# Subtract 12 hours to the picture's EXIF info
# exiftool "-AllDates-=0:0:0 12:0:0" -verbose *.jpg

photographer=""
# photographer="David"

mkdir -p rename

count=0
for video in *.mp4; do
    let "count+=1"
    # echo $video

    originalname="${video%.*}"
    newname="${video%.*}_${photographer}"

    echo "Original Name: $video"
    echo "New Name: $newname.mp4"

    if [ ! -z $photographer ]; then
        mv "$video" "rename/${newname}.mp4"
    fi
done

count=0
for video in *.avi; do
    let "count+=1"
    # echo $video

    originalname="${video%.*}"
    newname="${video%.*}_${photographer}"

    echo "Original Name: $video"
    echo "New Name: $newname.avi"

    if [ ! -z $photographer ]; then
        mv "$video" "rename/${newname}.avi"
    fi
done

count=0
for video in *.mov; do
    let "count+=1"
    # echo $video

    originalname="${video%.*}"
    newname="${video%.*}_${photographer}"

    echo "Original Name: $video"
    echo "New Name: $newname.mov"

    if [ ! -z $photographer ]; then
        mv "$video" "rename/${newname}_$(du -h "$video" | awk '{ print $1}').mov"
    fi
done

count=0
mkdir -p rename
for picture in *.jpg; do
    let "count+=1"
    echo $picture

    originalname="${picture%.*}"
    xpath=${picture%/*}
    pxwidth=$(exif $picture | grep "Pixel X Dimension" | cut -d "|" -f2)
    pxheight=$(exif $picture | grep "Pixel Y Dimension" | cut -d "|" -f2)
    dateTaken=$(exif $picture | grep "Date and Time (Digit" | cut -d "|" -f2 | cut -d " " -f1)

    if test -z "$dateTaken"; then
        echo "Date/Time not found for $picture"
    else
        datetaken="${dateTaken//:/-}"

        timeTaken=$(exif $picture | grep "Date and Time (Digit" | cut -d "|" -f2 | cut -d " " -f2)
        timetaken="${timeTaken//:/.}"

        if test -z "$pxwidth" || test -z "$pxheight"; then
            newname="$(echo $datetaken)_$(echo $timetaken)_$(du -h "$video" | awk '{ print $1}')"
        else
            newname="$(echo $datetaken)_$(echo $timetaken)_$(echo $pxwidth)x$(echo $pxheight)_$(du -h "$video" | awk '{ print $1}')"
        fi

        echo "Original Name: $picture"
        echo "New Name: $newname.jpg"

        if [[ -e $newname.jpg || -L $newname.jpg ]]; then
            i=1
            while [[ -e $newname-$i.jpg || -L $newname-$i.jpg ]]; do
                let i++
            done
            newname=$newname-$i
            echo "New Numbered Name: $newname"
            echo " "
        fi

        if [ ! -z $photographer ]; then
            mv "$picture" "rename/${newname}_${photographer}.jpg"
        else
            mv "$picture" "rename/${newname}.jpg"
        fi
    fi
done

Originally Posted on November 15, 2022
Last Updated on August 17, 2024
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.

Related

Code Mac OS X Shell Mac OSX UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

Ektron Metrics – User Count By User Group

Posted on May 6, 2013October 26, 2015

Part of the Ektron Metrics Script, this query will help with metrics to give you an idea of how often your users login. SET NOCOUNT ON DECLARE @month INT ,@year INT ,@start_date DATETIME ,@end_date DATETIME SET @month = ( SELECT CASE WHEN MONTH(GETDATE()) = ‘1’ THEN ’12’ ELSE MONTH(GETDATE()) -…

Read More

TaskKill App List

Posted on October 15, 2013October 26, 2015

taskkill /f /im pdfpro7hook.exe taskkill /f /im searchprotocolhost.exe taskkill /f /im sgnmaster.exe taskkill /f /im apmsgfwd.exe taskkill /f /im apntex.exe taskkill /f /im apoint.exe taskkill /f /im jusched.exe taskkill /f /im openvpn-gui.exe taskkill /f /im shstat.exe taskkill /f /im udaterui.exe taskkill /f /im hidfind.exe taskkill /f /im hkcmd.exe taskkill /f…

Read More

Azure CLI – Convert VM Dynamic IP to Static IP

Posted on April 5, 2018

If you create your VM with Dynamic IPs DHCP will grab the first available IP but some VMs are best on a static IP. This script below will get the existing IP of the ipconfig and reassign it to the same ipconfig as a static IP. Dynamic_To_Static () { nic="$4"…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes