Compare all file sizes of 2 directories in bash
Sometimes it happens that for some reason the process of copying many files (i.e. to ext开发者_运维技巧ernal HDD; using Nautilus file manager) crashes. If I then start it again, I use to ignore already existing files, though some of them were not copied 100%. So the properties window shows me "460 Files (225 GB)" in source folder and "460 Files (222 GB)" in destination folder...
How do I now find out which files have only been copied partially (maybe using ls
and diff
)?
If you have rsync
available, that works just fine between two local directories.
for f1 in dir1/*
do
f2="dir2/${f##*/}"
if [[ $(sum "$f1") != $(sum "$f2") ]]
then
printf 'File %s does not match %s\n' "$f1" "$f2"
fi
done
Or you could use this as your test:
if ! diff -q "$f1" $f2" >/dev/null
i modified dennis' code. it compares file sizes. Faster but not safer then comparing checksums..
source=/???
target=/???
for i in "$source"/*
do
f1=`stat -c%s $i`
f2=`stat -c%s $target/${i##*/}`
if [ "$f1" = "$f2" ]; then
echo "$i" "$f1" VS "$target/${i##*/}" "$f2" "====>>>" "OK"
else
echo "$i" "$f1" VS "$target/${i##*/}" "$f2" "====>>>" "BAD"
fi
done
精彩评论