recursively compare the contents of 2 directories in CentOS 7

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:

[[email protected] 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/ /home/user/nodejs_apps/angular2-esnext-starter/dist/client/ 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/ /home/user/nodejs_apps/angular2-esnext-starter/dist/client/ [[email protected] 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/ /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/ 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/ /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/ [[email protected] angular2_oauth_seed_app]$  


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


diff -r /home/user/nodejs_apps/angular2-esnext-starter/dist/client/ /home/user/nodejs_apps/angular2_oauth_seed_app/dist/client/

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:

$ md 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
< 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.

Category: centos Time: 2016-07-28 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.153 (s). 12 q(s)