rsync
is a good first choice if you want to copy all files and subdirectories under a directory. It does have an option for not overwriting files, the -b
backup option.
However, by default the backup is using a naming scheme that's not useful for this purpose (an added ~
character at the end of the filename, which some tools are hiding as unneeded backup files).
There is an option to change it (--suffix newending
), which can be anything, but it's still tacked on at the end, and not removing any previous extension. If that works for you, this is an easy job for rsync
. Note that it's a proper backup - files with the same names that are otherwise identical will not have two copies.
For example, in your case two commands would be needed to populate the destination from two sources:
rsync -av "Folder 1/" "New Folder/"
rsync -av -b --suffix -copy.txt "Folder 2/" "New Folder/"
Note the peculiar quoting required for the files with white spaces, and the ending / denoting the contents of the directory (starting under the directory, not including it).
Files that are already present from Folder 1 will be tacked on a -copy.txt
such as:
; ls -R1 New\ Folder
'New Folder':
f1.txt
f1.txt-copy.txt
f2.txt
f2.txt-copy.txt
Update:
Both commands essentially synchronise from the first directory to the second, and the additional command would indeed overwrite anything present in the destination, the backup option changes this so that the file that would otherwise be destroyed is kept as a backup. So indeed, the files from the second line would retain their names. This still might be useful for the original purpose if the commands were run in a different order.
That is, if you use rsync with the backup and suffix option - then the destination will have the azad.txt
file replaced, but the backup option would keep the previous file in the destination renamed with the new suffix.
.txt
files? Do I understand correctly: you want all files in a single target directory with no subdirs?