user2517676
user2517676

Reputation: 989

Finding the Files with the Same Name and Sub-Directories But Different Contents in Two Main Directories

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.

Upvotes: 0

Views: 107

Answers (1)

Paul Evans
Paul Evans

Reputation: 27567

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

Upvotes: 1

Related Questions