Quote:
Originally Posted by Nick-us
I will try to explain what I need to do.
I have 2 folders that are backups from different months of the same Linux:
LinuxA
LinuxB
I want to know what was modified in LinuxB compared to LinuxA
I read on the Internet that people indicate the diff command, But reading the diff manual doesn't seem right
"GNU diff - compare files line by line"
The Comparison I believe I need is to compare the files by date modified and if different, that file has certainly changed. Of course Check files that exist in one folder and do not exist in the other.
Does anyone have any idea how I can do this?
|
To compare the files in both trees you can
use "find" to walk down each tree and obtain the checksum for each file and redirect it into a file.
Code:
LinuxA=<path-to-some-tree>
LinuxB=<path-to-some-other-tree>
for TREE in ${LinuxA} ${LinuxB}
do
find ${TREE} -type f -exec md5sum {} \;
done > checksum.lis
Each record will look like "checksum filepath".
To see which files are the same, extract the checksums from the checksum file:
Code:
$ cat checksum.lis | awk '{print $1}' | sort | uniq -c | grep -v ' 1 ' | awk '{print $2}' > duplicate.checksums
which would eliminate all the checksums that are singletons. Locate these files using
Code:
$ grep -f duplicate.checksums checksum.list
If you're interested in finding the files that are different -- or do not exist in one of the trees -- you can use:
Code:
$ cat checksum.lis | awk '{print $1}' | sort | uniq -c | grep ' 1 ' | awk '{print $2}' > lonely.checksums
$ grep -f lonely.checksums checksum.lis
If you're looking for files that exist in LinuxA but not in LinuxB, you combine some of the above code and do something like:
Code:
LinuxA=<path-to-some-tree>
LinuxB=<path-to-some-other-tree>
for TREE in ${LinuxA} ${LinuxB}
do
find ${TREE} -type f -exec md5sum {} \;
done > checksum.lis
cat checksum.lis | grep ${LinuxA} | while read FP
do
FN=$( basename ${FP} )
if [ ! -e ${LinuxB}/${FP} ]; then
echo "${FP} does not exist under ${LinuxB}."
fi
done
(Note: the above
should work but I haven't tested it.)
You could add tests in the above to grep for and compare checksums for the cases where the files is found under
both trees and determine whether the file has been modified. Obviously, if you want to check if a file in the "LinuxB" tree doesn't exist in "LinuxA", you'd swap the names of the trees in the code.
HTH...