문제

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

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top