When two or more identically named folders are to be copied into or moved to the same location, the default option either in the GUI file manager, or using in a terminal cp -r --backup=numbered or rsync --backup , is to merge the contents of these folders.

Is there any native command to make progressively numbered copies of the actual directories instead, like say folder_copy_1, folder_copy_2 and so on, similar to what happens in windows?

  • It would help if you told us what your GUI file manager. – Anthon Jun 16 '13 at 10:36

Assuming by "native" you mean "commonly installed with the base system", then no, there isn't a specific tool for that, but it's easy enough to create a script of your own.

for f in "$@"; do
    b=$(basename "$f")
    # Grab any numeric suffix
    # Default to 0 if there is no suffix
    case n in *[!0-9]* | '' ) n=0;; esac
    e=$(expr $n + 1)
    cp "$f" "${b%$n}$e"

This should hopefully work in any reasonably recent POSIX shell.

  • And yes,by "native" I did actually mean "installed with the base system",because in these circumstances merging folders is usually not what I'm after,I would find more logical to have numbered copies of the original folder. – springstack25 Jun 17 '13 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.