查找具有相同名称和子目录但两个主要目录中的不同内容的文件

时间:2021-02-04 16:36:57

I have two main directories (/home/Rash/A and /home/Rash/B) of the same CPP project. However, some .cpp and .h files inside B directory have been modified. My question is how can I know which .cpp and .h files of B directory are different with their identical ones in A? I mean with the same file names and sub directories. I am more looking for a command or script which compares the contents of the files with the same names and subdirectories in A and B and reports me the files with differences in terms of their contents.

我有两个相同CPP项目的主目录(/ home / Rash / A和/ home / Rash / B)。但是,B目录中的某些.cpp和.h文件已被修改。我的问题是如何知道B目录中哪些.cpp和.h文件与A中的相同?我的意思是使用相同的文件名和子目录。我更希望找到一个命令或脚本,用于比较A和B中相同名称和子目录的文件内容,并报告文件内容方面的差异。

1 个解决方案

#1


1  

You want something like this:

你想要这样的东西:

for i in /home/Rash/A/*.{cpp,h}; do
    j=${i//A/B/}
    if [ -e $j ]; then
        echo comparing $i and $j
        diff $i $j
    fi
done

#1


1  

You want something like this:

你想要这样的东西:

for i in /home/Rash/A/*.{cpp,h}; do
    j=${i//A/B/}
    if [ -e $j ]; then
        echo comparing $i and $j
        diff $i $j
    fi
done