-1

A build process in an app is generating a directory structure in a CentOS 7 machine. I have copied the app to a second location in the same server, made a few changes, and then run the build process again. I want to compare results of the build processes. What specific commands need to be typed into the terminal in order to recursively compare all the nested directories and files within the directories created by each build process?

I want to see:
1.) Which files are only in Directory1 but NOT in Directory2
2.) Which files are only in Directory2 but NOT in Directory1

Directory1 is: /home/user/nodejs_apps/angular2_oauth_seed_app/dist
Directory2 is: /home/user/nodejs_apps/angular2-esnext-starter/dist

Here is what I typed so far, which seems to be giving the same results in both directions, which would seem to be wrong:

[user@localhost angular2_oauth_seed_app]$ diff -r /home/user/nodejs_apps/angular2_oauth_seed_app/dist /home/user/nodejs_apps/angular2-esnext-starter/dist | grep /home/user/nodejs_apps/angular2_oauth_seed_app/dist
diff -r /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/boot.js /home/user/nodejs_apps/angular2-esnext-starter/dist/client/boot.js
diff -r /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/boot.js.map /home/user/nodejs_apps/angular2-esnext-starter/dist/client/boot.js.map
diff -r /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/index.html /home/user/nodejs_apps/angular2-esnext-starter/dist/client/index.html
diff -r /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/vendor.js.map /home/user/nodejs_apps/angular2-esnext-starter/dist/client/vendor.js.map
[user@localhost angular2_oauth_seed_app]$ diff -r /home/user/nodejs_apps/angular2-esnext-starter/dist  /home/user/nodejs_apps/angular2_oauth_seed_app/dist | grep /home/user/nodejs_apps/angular2-esnext-starter/dist
diff -r /home/user/nodejs_apps/angular2-esnext-starter/dist/client/boot.js /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/boot.js
diff -r /home/user/nodejs_apps/angular2-esnext-starter/dist/client/boot.js.map /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/boot.js.map
diff -r /home/user/nodejs_apps/angular2-esnext-starter/dist/client/index.html /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/index.html
diff -r /home/user/nodejs_apps/angular2-esnext-starter/dist/client/vendor.js.map /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/vendor.js.map
[user@localhost angular2_oauth_seed_app]$ 
2

The files you are seeing there are present in both directories but are different; that's why they show up.

If you run one of those diff commands you can see what it thinks are different

eg

diff -r /home/user/nodejs_apps/angular2-esnext-starter/dist/client/vendor.js.map /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/vendor.js.map

If you want to see files that are in one and not the other then the line begins with Only in

So in this simple tree:

$ mkdir X Y
$ touch X/1 Y/2
$ echo a file > X/a
$ echo different > Y/a
$ echo same > X/b
$ echo same > Y/b

We have files that are present in one directory but not the other, a file that is present in both but is different, and a file present in both that is the same.

$ diff -r X Y
Only in X: 1
Only in Y: 2
diff -r X/a Y/a
1c1
< a file
---
> different
$ 

We can see it's reported on the two unique files, and the file that has changed. The file that is identical is not reported on.

  • OK. So if I want to see what is different in both versions of each of those named files, how can I? I hesitate to just open them up in two gedit windows because the files are huge. – FirstOfMany Jul 28 '16 at 22:04
  • That's what the < and > lines are in the output; the difference between them. – Stephen Harris Jul 28 '16 at 22:06
  • I do not think that we are understanding each other. I want to know what is different in each version of boot.js, for example. – FirstOfMany Jul 28 '16 at 22:19
  • That is what is shown on those lines. In this example it's letting me that X/a and Y/a are different; the line that is difference is in line 1 and that it says a file in the first and different in the second. diff -r does this for every file in the two trees and reports on those differences. If you want the output in a different form then diff -cr will produce some context around the lines. ("context diff") – Stephen Harris Jul 28 '16 at 22:21
  • In your answer, X, Y, a, and b have no meaning for me. Can you express it in terms of what those variables actually represent. So that, for example, I can see how to compare the file in first/path/to/boot.js with the file in second/path/to/boot.js to see what is different in the two files. – FirstOfMany Jul 28 '16 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.