Skip to main content
added 26 characters in body
Source Link
Allan
  • 104.4k
  • 33
  • 206
  • 470

You can do this in Terminal with a short script:

for file in /source/directory; do $time=date +%s; if [[ -f /target/directory/$file ]]; then cp $file ${file}-${time}; else cp $file /target/directory/$file; fi; done

This will check to see if the file already exists and if it does it will append the time in seconds to the destination filename and copy it over. The advantage this has over just doing a -v verbose or -n no overwrite is that it will ensure there are no multiple duplicates.

The advantageAdditionally, this has isthe added advantage that if the filenames are the same but are different in size/content. This will give it gives you the opportunity to see the potential dupes and deal with them.

You can do this in Terminal with a short script:

for file in /source/directory; do $time=date +%s; if [[ -f /target/directory/$file ]]; then cp $file ${file}-${time}; else cp $file /target/directory/$file; fi; done

This will check to see if the file already exists and if it does it will append the time in seconds to the filename and copy it over. The advantage this has over just doing a -v verbose or -n no overwrite is that it will ensure there are no multiple duplicates.

The advantage this has is if the filenames are the same but are different in size/content. This will give you the opportunity to see the potential dupes and deal with them.

You can do this in Terminal with a short script:

for file in /source/directory; do $time=date +%s; if [[ -f /target/directory/$file ]]; then cp $file ${file}-${time}; else cp $file /target/directory/$file; fi; done

This will check to see if the file already exists and if it does it will append the time in seconds to the destination filename and copy it over. The advantage this has over just doing a -v verbose or -n no overwrite is that it will ensure there are no multiple duplicates.

Additionally, this has the added advantage that if the filenames are the same but are different in size/content it gives you the opportunity to see the potential dupes and deal with them.

Source Link
Allan
  • 104.4k
  • 33
  • 206
  • 470

You can do this in Terminal with a short script:

for file in /source/directory; do $time=date +%s; if [[ -f /target/directory/$file ]]; then cp $file ${file}-${time}; else cp $file /target/directory/$file; fi; done

This will check to see if the file already exists and if it does it will append the time in seconds to the filename and copy it over. The advantage this has over just doing a -v verbose or -n no overwrite is that it will ensure there are no multiple duplicates.

The advantage this has is if the filenames are the same but are different in size/content. This will give you the opportunity to see the potential dupes and deal with them.