Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .