129

Have two folders with approx. 150 java property files.

In a shell script, how to compare both folders to see if there is any new property file in either of them and what are the differences between the property files.

The output should be in a report format.

5 Answers 5

233

To get summary of new/missing files, and which files differ:

diff -arq folder1 folder2

a treats all files as text, r recursively searched subdirectories, q reports 'briefly', only when files differ

1
  • @reko_t is there any way to run this via Java Commented Aug 31, 2017 at 5:11
28

diff -r will do this, telling you both if any files have been added or deleted, and what's changed in the files that have been modified.

0
8

I used

diff -rqyl folder1 folder2 --exclude=node_modules

in my nodejs apps.

0

Could you use dircmp ?

-2

Diff command in Unix is used to find the differences between files(all types). Since directory is also a type of file, the differences between two directories can easily be figure out by using diff commands. For more option use man diff on your unix box.

 -b              Ignores trailing blanks  (spaces  and  tabs)
                 and   treats  other  strings  of  blanks  as
                 equivalent.

 -i              Ignores the case of  letters.  For  example,
                 `A' will compare equal to `a'.
 -t              Expands <TAB> characters  in  output  lines.
                 Normal or -c output adds character(s) to the
                 front of each line that may adversely affect
                 the indentation of the original source lines
                 and  make  the  output  lines  difficult  to
                 interpret.  This  option  will  preserve the
                 original source's indentation.

 -w              Ignores all blanks (<SPACE> and <TAB>  char-
                 acters)  and  treats  all  other  strings of
                 blanks   as   equivalent.    For    example,
                 `if ( a == b )'   will   compare   equal  to
                 `if(a==b)'.

and there are many more.

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