比较两个文件夹,里面有很多文件


103

有两个文件夹。150个Java属性文件。

在shell脚本中,如何比较两个文件夹以查看它们中是否有任何新的属性文件,以及这些属性文件之间的区别是什么。

输出应为报告格式。

Answers:


202

要获取新文件/丢失文件的摘要以及哪些文件不同:

diff -arq folder1 folder2

a仅当文件不同时,将所有文件视为文本,r递归搜索的子目录,q“简短地”报告


@reko_t有任何方法可以通过Java
Kasun Siyambalapitiya '17

27

diff -r 会执行此操作,告诉您是否已添加或删除任何文件,以及已修改文件中的更改内容。


5

我用了

diff -rqyl folder1 folder2 --exclude=node_modules

在我的nodejs应用中。



-1

Unix中的Diff命令用于查找文件(所有类型)之间的差异。由于目录也是文件的一种,因此可以使用diff命令轻松找出两个目录之间的差异。有关更多选项,请在您的Unix框中使用man diff

 -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)'.

还有更多。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.