S
S
syxoi2016-04-09 11:51:37
linux
syxoi, 2016-04-09 11:51:37

Script (or program) to compare data in two directories?

Hello!
There are a bunch of files that are packed into an archive on one machine, and transferred to another, unpacked on it, but if you look at the original and already unpacked files, the size of the folders (du -s folder) are different! Therefore, I decided to try to write the following script:

#!/bin/bash
DIR1=New
DIR2=New1
CAC="sha512sum"
IFS=$'\n' array0=( $(find "$DIR1" -type f ) )
IFS=$'\n' array1=( $(find "$DIR2" -type f) )
#echo ${array0[@]}
for rec0 in ${array0[@]}; do
#echo `$CAC $rec0`
IFS=$'\n' c0=( $($CAC $rec0) )
#echo ${c0[@]}
done
for rec1 in ${array1[@]}; do
IFS=$'\n' c1=( $($CAC $rec1) )
#echo ${c1[@]}
done
#for rec2 
#if ; then
#echo 'su';
#else
#echo 'e';
#fi
#for t in ${c0[@]; do
#for b in ${c1[@]; do
#if ; then
#echo 'right'
#else
#echo 'left'
#fi

the script reads the data in the folders specified in the DIR1 and DIR2 variables, creates their checksum and checks these checksums, if the number of files is different, or the checksums differ, then we sound the alarm. But I could not bring this script to mind. Please tell me some method for this task.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Saboteur, 2016-04-09
@syxoi

DU does not show the size of files and folders, but how much they occupy on the disk.
For example, if you have a larger block size on the second disk, then du will always show more.
In your case, it's better to synchronize everything via rsync with compression - more reliable. And in general, there are many ready-made solutions for synchronizing two directories that have already taken care of all childhood illnesses, such as file names with dangerous characters, and other things.
You can also do one-way synchronization.
Or simplify the script, for example to this

find DIR1/* -exec md5sum {} \; > file1.lst
find DIR2/* -exec md5sum {} \; > file2lst
diff file1.lst file2.lst

U
uvelichitel, 2016-04-09
@uvelichitel

rsync?

D
Dmitry, 2016-04-09
@kashamalasha

diff dir1 dir2 cannot be used?

S
sim3x, 2016-04-09
@sim3x

If not diff/rsync then git

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question