Z
Z
zapolya2018-12-19 14:14:36
linux
zapolya, 2018-12-19 14:14:36

How to create a hard link to a file?

Script renames PHOTO1.JPG files to photo0001.jpg

#!bin/bash
rename ‘y/A-Z/a-z/‘ *.JPG
rename ‘s/photo/photo000/g’ *.jpg

How to make a hard link to Files PHOTO1.JPG, PHOTO2.JPG... PHOTO123.JPG
Renamed crookedly, you need to get photo0123.jpg from PHOTO123.JPG, but displays photo000123
How to fix it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
3
3vi1_0n3, 2018-12-20
@zapolya

#!/bin/bash

for fn in *.JPG
do
    fn_small=${fn,,}
    num=${fn_small//[a-z.]}
    mv $fn ${fn_small/$num/$(printf "%04d" $num)}
done

P
planc, 2018-12-19
@planc

horror, why did I do this ...
we generate a mountain of files for the test:

#!/bin/bash

for fname in PHOTO*;
do
    number=$(echo $fname | sed -r 's/PHOTO([0-9]+)\.JPG/\1/');
    echo $fname - $number;
    case $number in
        ?)
            newname='photo000'$number.jpg
            ;;
        ??)
            newname='photo00'$number.jpg
            ;;
        ???)
            newname='photo0'$number.jpg
            ;;
        ????)
            newname='photo'$number.jpg
            ;;
    esac
    echo "old: $fname new: $newname";
    # mv $fname $newname
done

H
Heizenberg, 2018-12-19
@Heizenberg

Then like this
rename -e 's/\d+/sprintf("%04d",$&)/e' -- *.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question