比较内容中包含许多文件的两个文件夹

时间:2009-10-29 15:36:04

标签: unix shell diff

有两个大约的文件夹。 150个java属性文件。

在shell脚本中,如何比较两个文件夹以查看其中任何一个文件夹中是否存在任何新属性文件以及属性文件之间的差异。

输出应采用报告格式。

5 个答案:

答案 0 :(得分:179)

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

diff -arq folder1 folder2

a将所有文件视为文本,r递归搜索子目录,q简要报告',仅在文件不同时

答案 1 :(得分:26)

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

答案 2 :(得分:3)

我用过

diff -rqyl folder1 folder2 --exclude=node_modules

在我的nodejs应用程序中。

答案 3 :(得分:0)

您可以使用dircmp吗?

答案 4 :(得分:-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)'.

还有更多。