Question

There are thousands of files in my src folder.I have src and src_temp folders name, both are same in terms of files but files cksum may differ.

I want to compare files in the folder against cksum so that i can see which files are different.

Please let me know the way.

I checked this link as well but dont know which one is good to check thousands of files.

Found :

$ # go to directory dir1
$ cd dir1
$
$ ls | sort | xargs cksum
1958180199 14 file1
1994293486 14 file2
1996893289 14 file3
$
$ # now do the same for directory dir2
$ cd ../dir2
$
$ ls | sort | xargs cksum
1958180199 14 file1
1994293486 14 file2
1996893289 14 file3

then diff of files.. .there are thousands of file. Can we have any other good approach

Était-ce utile?

La solution

Files:

$ cat f1/foo.txt   
foo
$ cat f1/bar.txt
bar
$ cat f2/foo.txt 
fooX
$ cat f2/bar.txt
bar

Script:

for f in f1/*
do
  b=$(basename $f)
  m1=$(md5sum f1/$b | cut -d' ' -f1)
  m2=$(md5sum f2/$b | cut -d' ' -f1)
  if [ "$m1" != "$m2" ]
  then
    echo $b is different
  fi
done

Output:

foo.txt is different

Autres conseils

Rsync can do this comparison for you

rsync -n -avrc folder1 folder2

If you have your other folder on some other machine

rsync -n -avrc folder1/* server2:/home/myuser/folder2

-n option just does comparison without doing actual rsync

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top