View previous topic :: View next topic |
Author |
Message |
McLink Apprentice
Joined: 02 Feb 2008 Posts: 181 Location: /dev/chair
|
Posted: Mon Nov 24, 2008 11:22 am Post subject: [Mini-TIP] Copy without overwriting |
|
|
cp, by default, overwrites the destination file. Using the -i option, it prompts you if you for input when it's about to overwrite something, so you can say "n" and hit enter to not overwrite the destination. But what if you want to merge two directories containing thousands of files, without overwriting any destination files? What you want is basically the opposite of the --force option, but such an option does not exist with the default cp.
Well, there's a simple solution: yes. If you want to prevent cp from overwriting any destination files, you can use the following: Code: | yes n | cp -i srcdir/* destdir |
It basically tells cp to prompt for overwriting, and programmatically feeds it "n"'s, asserting no destination files are overwritten.
Trivia: this type of behaviour is exactly what yes was created for in the first place. _________________
Mc'abit wrote: | Islam isn't the problem, religion is. |
|
|
Back to top |
|
|
michel7 Guru
Joined: 04 May 2006 Posts: 461 Location: localhost
|
Posted: Mon Nov 24, 2008 11:43 am Post subject: |
|
|
nice tip! thanks! _________________ Software is like sex. It's better when it's free |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|