将目录与 cksum 进行比较以在文件名中包含空格

Comparing directories with cksum to include spaces in file names

提问人:Alex Ixeras 提问时间:12/16/2022 更新时间:12/16/2022 访问量:39

问:

我最近使用 rsync 传输了一个有很多子目录的大目录;总共有几GB大小。有几千个文件要比较。试图查看一切是否顺利,以及每个文件是否都在它应该在的位置,即。我有一个原始目录的克隆。

我想将此脚本 () 提供给两个目录进行比较:compare_directoriescompare_directories dir1 dir2

#!/bin/bash

if [[ -z $2 ]];
then 
    # simple help text with no error checking
    echo "compare_directories dir1 dir2"
    echo "   dir1  directory with files copied from"
    echo "   dir2  directory with files copied to"
else
    export FROM=$1
    export TO=$2
    cnt=0
    for fname in *
    do
        from=$(cksum $FROM/$fname)
        from=${from%% *}
        to=$(cksum $TO/${fname})
        to=${to%% *}
        cnt=$(($cnt + 1))
        [ $(($cnt % 5)) -eq 0 ] && echo "$cnt files processed"
        [ "$from" = "$to" ] && continue
        echo "failure on file $fname"
    done
fi

带有“已处理的 x 个文件”的行只是为了表示每 5 个已处理文件后打印一个计数器,以指示比较仍在运行。

我使用这个脚本来比较每个文件的校验和,但它不喜欢文件名中的空格,而且我不完全确定它是否有效运行。

性能 比较 文件名 校验和

评论

0赞 Alex Ixeras 12/16/2022
我发现最简单的解决方案是用引号包围处理文件名的出现,例如 .另一方面,我注意到该脚本不会遍历所有目录,而是“卡”在当前级别。from=$(cksum "$FROM/$fname")

答: 暂无答案