Skip to content

Instantly share code, notes, and snippets.

@TilBlechschmidt
Created February 9, 2022 14:21
Show Gist options
  • Save TilBlechschmidt/9a2beeec8e9df9f97f3e6af793dfb71b to your computer and use it in GitHub Desktop.
Save TilBlechschmidt/9a2beeec8e9df9f97f3e6af793dfb71b to your computer and use it in GitHub Desktop.
GoPro file renaming
#!/bin/sh
# For some reason GoPros name their files in a pretty shitty manner.
# The initial file of a recording starts with GOPR#### where the # represent the recording number.
# Each following segment (each segment can only be 4GB in size even when using ExFAT) receives a name like this:
# GP**#### where the # are the same as the initial file and the * are the segment number.
# Additionally, the modification date of the files does not seem to be set properly so sorting by that yields nothing either.
#
# This script renames the GP**####.MP4 files into GP####-**.mp4
for file in GP*; do
base=$(basename $file ".MP4")
file1="${base#*??}"
file2=${file1#*??}
file3=${file1%*$file2}
echo mv -v "$file" "${base%*$file1}${file2}"-"$file3".mp4
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment