Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
It would help if you told us what your GUI file manager. –  Anthon Jun 16 '13 at 10:36

1 Answer 1

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.

#!/bin/sh
for f in "$@"; do
    b=$(basename "$f")
    # Grab any numeric suffix
    n=${b##*[!0-9]}
    # 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"
done

This should hopefully work in any reasonably recent POSIX shell.

share|improve this answer
    
Thanks-as for the file manager,I'm using Nautilus. –  springstack25 Jun 17 '13 at 11:30
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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