bash 包含源的两个完整目录之间的差异并将结果输出到文本文件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9169161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Diff between two entire directories that contain source and output the result in a textfile
提问by domlao
I have two directories that contain directories and source files. One directory contains the modified source code and the other one is unmodified source code. And I want to see what source code was modified and see the modified part of the code. And I also want to output the result to a single text file.
我有两个包含目录和源文件的目录。一个目录包含修改后的源代码,另一个目录是未修改的源代码。而且我想查看修改了哪些源代码并查看代码的修改部分。而且我还想将结果输出到单个文本文件。
I know I have to use the diff tool but I'm not sure what options should I use. Do I need to create a script for this, or is there a one line command to do the task?
我知道我必须使用 diff 工具,但我不确定应该使用哪些选项。我需要为此创建一个脚本,还是有一个单行命令来完成这项任务?
回答by Alex P.
You might want to do something like
你可能想做类似的事情
diff -rw directory1 directory2 > diff.txt
where -rmakes it recursive (so all sub-directories are scanned, too), -wis for ignoring all white-space (e.g., stray spaces or tabs somebody inserted), and > diff.txtredirects your output to the file diff.txt. More options can be found in the man page:
其中-r使其递归(因此也扫描所有子目录),- w用于忽略所有空白(例如,有人插入的杂散空格或制表符),并且> diff.txt将您的输出重定向到文件diff .txt。可以在手册页中找到更多选项:

