I have many identical files in two (local) devices, and it happens that I have renamed some, only in one device (A). I found the following way to rename the identical files in the other device (B), according to the new names in device A, so that at the end I have identical both files and namefiles, without deleting or copying anything, but only renaming.
Indeed I found an interesting answer is here from Hai Vu (the second answer).
The script works, but there are two problems:
- with spaces in filenames: the names are truncated by spaces. and
- with apos (') in filenames
The script (rename-identical-files.awk) is
/^total/ {next} # Skip the first line (which contains the total, of ls -l)
{
if (name[$5] == "") {
name[$5] = $NF
print "# File of size", $5, "should be named", $NF
} else {
printf "mv '%s' '%s'\n", $NF, name[$5]
}
}
and it is called from command line (in the destination folder):
awk -f ~/rename-identical-files.awk <(ls -l /model-folder-path) <(ls -l) | sh
The problem seems ls command, that has limits (at least) with spaces and other characters in filenames.
What code should I write, to avoid space (and apostrophes) problems?
diff
orcomm
the files. – Ed Morton Jan 03 '21 at 17:53