Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have some files on the Desktop

/Desktop/F1/T1 
/Desktop/F2/T2

I want to copy those files to another folder like Destination but If the destination contains a file with same name I want to backup it to a folder named /Backup

So if a file named /Desktop/F1/T1 Already Exist on /Destination/F1/T1 it should be moved as Backup/F1/T1 I Need a Linux Script for this (actually Unix), The Command cp -b doesn't work on Mac.

share|improve this question

migrated from stackoverflow.com Nov 29 '12 at 13:08

This question came from our site for professional and enthusiast programmers.

    
Anything that you have tried ? –  GajananH Nov 29 '12 at 8:47
    
This is very basic, at least try something yourself. This isn't a script request service! –  iiSeymour Nov 29 '12 at 8:59
add comment

2 Answers

cp -n doesn't overwrite files that already exist.

cd ~/Desktop/
cp -Rn * ~/Destination/
cp -R * ~/Backup/
share|improve this answer
add comment

Try rsync with the --backup and --backup-dir flags.

share|improve this answer
add comment

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.