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

Maybe I am missing something, but I'd like a diff between two directories to create files that don't exist, but not remove files that do. So, given something like:

./a/foo
./b/bar

This command:

diff -urN a b

Will show:

diff -urN a/bar b/bar
--- a/bar       1969-12-31 17:00:00.000000000 -0700
+++ b/bar       2012-05-22 10:09:05.221356000 -0600 @@ -0,0 +1 @@
+bar 
diff -urN a/foo b/foo
--- a/foo       2012-05-22 10:08:54.133138000 -0600
+++ b/foo       1969-12-31 17:00:00.000000000 -0700 @@ -1 +0,0 @@
-Foo

What I'd like is essentially this:

diff -urN a/bar b/bar
--- a/bar       1969-12-31 17:00:00.000000000 -0700
+++ b/bar       2012-05-22 10:09:05.221356000 -0600 @@ -0,0 +1 @@
+bar

I want new files that are in b but not a to be created, but files that are in a but not b ignored. Is that possible with diff?

Thanks!

share|improve this question
    
I do understand why the current behavior makes sense, just wondering if there's another way as well. – Christoph May 22 '12 at 16:21
up vote 1 down vote accepted

I think you're looking for GNU diff's --unidirectional-new-file flag, instead of -N.

diff -ur --unidirectional-new-file a/bar b/bar
--- a/bar   1969-12-31 19:00:00.000000000 -0500
+++ b/bar   2012-05-22 12:39:33.000000000 -0400
@@ -0,0 +1 @@
+bar
Only in a: foo

If you really want to, you can pipe the output through grep -v '^Only in' to get rid of the last line, but it shouldn't hurt anything to leave it in.

share|improve this answer
    
Wow, how'd I miss that? I saw that option and read it, and for some reason my mind made it out to say the reverse of what it does say. Thanks! – Christoph May 22 '12 at 16:54
    
Actually this does work the wrong way. When I do that, it tries to create bar in b, which already exists. I can't just do -R either, since others work okay. Any ideas? – Christoph May 22 '12 at 17:51
    
I think I'm misunderstanding something. It sounds like you're generating a patch to turn a into b, then applying it to a directory that's already like b, rather than one that's like a. – Jander May 22 '12 at 18:11

You must log in to answer this question.

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