okay.... this is what ...gpt wrote up and from my testing it works. it
prompts me for the prefix text, adds the date, and the sequence.
#!/usr/bin/env bash
WORK_DIR="$HOME/Pictures/Rename"
cd "$WORK_DIR" || { echo "Could not change to directory: $WORK_DIR"; exit
1; }
TODAY=$(date +%Y-%m-%d)
# Prompt the user for a prefix
read -rp "Enter prefix for filenames (default: Photos): " PREFIX
PREFIX=${PREFIX:-Photos} # use default if input is empty
shopt -s nullglob # avoid literal patterns if no files
# Find the highest existing counter for today and prefix
MAX_COUNTER=0
for EXISTING in "${PREFIX}_${TODAY} - "*.*; do
[ -e "$EXISTING" ] || continue
BASENAME=$(basename "$EXISTING")
# Extract the number after the last ' - '
COUNTER_PART="${BASENAME##* - }"
COUNTER_PART="${COUNTER_PART%.*}" # remove extension
# Only consider it if it's a number
if [[ $COUNTER_PART =~ ^[0-9]+$ ]]; then
(( COUNTER_PART > MAX_COUNTER )) && MAX_COUNTER=$COUNTER_PART
fi
done
COUNTER=$((MAX_COUNTER + 1))
# Rename files
for FILE in *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG; do
[ -e "$FILE" ] || continue
EXT="${FILE##*.}"
EXT=$(echo "$EXT" | tr '[:upper:]' '[:lower:]')
NEW_NAME="${PREFIX}_${TODAY} - ${COUNTER}.${EXT}"
mv "$FILE" "$NEW_NAME"
echo "Renamed '$FILE' -> '$NEW_NAME'"
COUNTER=$((COUNTER + 1))
done
On Sat, Aug 16, 2025 at 11:49 AM Michael <[email protected]> wrote:
> okay... so what do you think.... will this work? chatgot says it will .
> #!/usr/bin/env bash
>
> # Label of the drive
> LABEL="photos"
>
> # Get the mountpoint for the volume with this label
> MOUNT_POINT=$(findmnt -n -o TARGET -S LABEL="$LABEL")
>
> if [ -z "$MOUNT_POINT" ]; then
> echo "Could not find a mounted volume with label: $LABEL"
> exit 1
> fi
>
> echo "Found $LABEL mounted at: $MOUNT_POINT"
>
> # Use the mounted directory as working dir
> WORKING_DIR="$MOUNT_POINT"
>
> cd "$WORKING_DIR" || { echo "Could not change to directory: $WORKING_DIR";
> exit 1; }
>
> # Define a loop counter
> COUNTER=1
>
> # Process all .txt files
> while IFS= read -r FILE; do
> # Store the directory of the file
> DIR=$(dirname "$FILE" | tr '[:upper:]' '[:lower:]')
>
> # Strip the file extension and convert to lowercase
> OLD_NAME=$(basename "$FILE" | sed 's/\.txt$//' | tr '[:upper:]'
> '[:lower:]')
>
> # Build the new filename
> NEW_NAME="${OLD_NAME}_${COUNTER}.txt"
>
> # Perform the renaming
> if mv "${DIR}/${OLD_NAME}.txt" "${DIR}/${NEW_NAME}"; then
> echo "Renamed '${DIR}/${OLD_NAME}.txt' -> '${DIR}/${NEW_NAME}'"
> COUNTER=$((COUNTER + 1))
> else
> echo "Failed to rename '$FILE'"
> exit 1
> fi
> done < <(find . -type f -name "*.txt" | sort -u)
>
> On Thu, Aug 7, 2025 at 2:33 PM Snyder, Alexander J <
> [email protected]> wrote:
>
>> I have actually written this a few times for things I've needed in my
>> homelab:
>>
>> This is the code (at a glance):
>> [image: image.png]
>>
>> I have attached the source file for you to use. Please make note that it
>> requires you to enter in your working directory (line 4) before it will
>> work as intended.
>>
>> --
>> Thanks,
>> Alex.
>>
>>
>>
>>
>> On Thu, Aug 7, 2025 at 10:06 AM Michael via PLUG-discuss <
>> [email protected]> wrote:
>>
>>> I was wondering, I need to rename a sequence of files from
>>> '<order>,jpg' '<order+1>,jpg' (etc)
>>> to
>>> '<name> - <name>.jpg' '<name> - <name>*sequence* <+1>'.jpg etc
>>> Would someone give me the proper bash command to do it?
>>> ---------------------------------------------------
>>> PLUG-discuss mailing list: [email protected]
>>> To subscribe, unsubscribe, or to change your mail settings:
>>> https://lists.phxlinux.org/mailman/listinfo/plug-discuss
>>>
>>
>
> --
> :-)~MIKE~(-:
>
--
:-)~MIKE~(-:
---------------------------------------------------
PLUG-discuss mailing list: [email protected]
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss