Ubuntu – Diff command to compare files which are in first directory only

diff()

I have 2 folders whose contents I want to compare. For instance I have folder 1 and folder 2. Folder 2 has a lot of new files + some files same as folder 1 but with some changes in contents of these files. Now, I want to compare folder 1 and folder 2 to get the list of folder 1 files which are changed or missing in folder 2.

When I run following command:

diff --brief -r folder1/ folder2/ > diff.txt

It also gives me the list of new files of folder 2.

I want to compare folder 1 and folder 2 to get the list of only those files of folder 1 which are missing or changed in folder 2.

How can I achieve this ?

Please don't recommend Meld, I already tried it and it's of no help. I figured, command line would be faster.

UPDATE

find folder1 -type f -exec diff --brief --from-file=folder2 {} +

doesn't give me the full file path of the differed/missing files.

Best Answer

The --from-file option might be of use:

$ diff -r --brief foo bar
Files foo/a and bar/a differ
Files foo/b and bar/b differ
Files foo/c and bar/c differ
Only in bar: d
$ diff --brief --from-file=bar foo/*
Files bar/a and foo/a differ
Files bar/b and foo/b differ
Files bar/c and foo/c differ

So, in your case, it would be:

diff --brief --from-file=folder2 folder1/*

There's also the --unidirectional-new-file option:

--unidirectional-new-file
      treat absent first files as empty

With it:

$ diff /tmp/foo/ /tmp/bar -r --brief --unidirectional-new-file
Files /tmp/foo/a and /tmp/bar/a differ
Files /tmp/foo/b and /tmp/bar/b differ
Files /tmp/foo/c and /tmp/bar/c differ