rename identical files (with different names) in different devices

You can use a zsh script (let we call “rename-identical-files.bash”) with a code like the following

#! /bin/zsh -
zmodload zsh/stat || exit
typeset -A size_to_name

CDPATH= cd -P -- "$model_folder" || exit
for f in *(ND.); do
  stat -LA size +size -- $f &&
    size_to_name[$size]=$f &&
    print -r "# File of size $size should be named ${(q)f}"

cd $OLDPWD || exit
for f in *(ND.); do
  stat -LA size +size -- $f &&
    (($+size_to_name[$size])) &&
    [[ $f != $size_to_name[$size] ]] &&
    print -r mv -i -- ${(qq)f} ${(qq)size_to_name[$size]}
#usage:  that-script /model-folder-path

then you can go to the folder where you want rename the files and do this terminal command:

~/rename-identical-files.bash /path/to/model/folder

in this way, before executing the command, you can see what could happen afterwards. If it’s all ok, do the command:

~/rename-identical-files.bash /path/to/model/folder | sh

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *