{"id":2297,"date":"2021-01-01T20:59:16","date_gmt":"2021-01-01T19:59:16","guid":{"rendered":"https:\/\/digitalia.culturanuova.net\/blog\/?p=2297"},"modified":"2022-05-31T17:28:18","modified_gmt":"2022-05-31T15:28:18","slug":"rename-identical-files-with-different-names-in-different-devices","status":"publish","type":"post","link":"https:\/\/digitalia.culturanuova.net\/blog\/?p=2297","title":{"rendered":"rename identical files (with different names) in different devices"},"content":{"rendered":"\n<p>You can use a zsh script (let we call &#8220;rename-identical-files.bash&#8221;) with a code like the following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#! \/bin\/zsh -\nzmodload zsh\/stat || exit\ntypeset -A size_to_name\nmodel_folder=${1?}\n\nCDPATH= cd -P -- \"$model_folder\" || exit\nfor f in *(ND.); do\n  stat -LA size +size -- $f &amp;&amp;\n    size_to_name&#91;$size]=$f &amp;&amp;\n    print -r \"# File of size $size should be named ${(q)f}\"\ndone\n\ncd $OLDPWD || exit\nfor f in *(ND.); do\n  stat -LA size +size -- $f &amp;&amp;\n    (($+size_to_name&#91;$size])) &amp;&amp;\n    &#91;&#91; $f != $size_to_name&#91;$size] ]] &amp;&amp;\n    print -r mv -i -- ${(qq)f} ${(qq)size_to_name&#91;$size]}\ndone\n#usage:  that-script \/model-folder-path<\/code><\/pre>\n\n\n\n<p>then you can go to the folder where you want rename the files and do this terminal command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~\/rename-identical-files.bash \/path\/to\/model\/folder<\/code><\/pre>\n\n\n\n<p>in this way, before executing the command, you can see what could happen afterwards. If it&#8217;s all ok, do the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~\/rename-identical-files.bash \/path\/to\/model\/folder | sh<\/code><\/pre>\n\n\n\n<p>cfr. <a href=\"https:\/\/unix.stackexchange.com\/questions\/627319\/avoid-spaces-and-apostrophes-problems-with-ls-in-a-awk-script#627328\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/unix.stackexchange.com\/questions\/627319\/avoid-spaces-and-apostrophes-problems-with-ls-in-a-awk-script#627328<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use a zsh script (let we call &#8220;rename-identical-files.bash&#8221;) with a code like the following then you can go to the folder where you want rename the files and do this terminal command: in this way, before executing the command, you can see what could happen afterwards. If it&#8217;s all ok, do the command: &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/digitalia.culturanuova.net\/blog\/?p=2297\" class=\"more-link\">Leggi tutto<span class=\"screen-reader-text\"> &#8220;rename identical files (with different names) in different devices&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[647,573],"tags":[657,215],"class_list":["post-2297","post","type-post","status-publish","format-standard","hentry","category-linux","category-sistema-operativo","tag-rename","tag-sync"],"_links":{"self":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2297"}],"version-history":[{"count":6,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2297\/revisions"}],"predecessor-version":[{"id":2629,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2297\/revisions\/2629"}],"wp:attachment":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}