这个想法是为目录中的所有文件(包括所有子目录)计算 SHA256 哈希,但排除另一个文本文件中指定的一些文件。
问题是,如果我指定要排除以下文件(参见代码下方),则只排除其中一个,而不是同时排除两者。
这是我的代码:
while read line
do
if [ $line_count -eq 0 ]
then
exclude_files=".*/$line$"
else
exclude_files="${exclude_files}\|.*/$line$"
fi
line_count=$(( $line_count + 1 ))
done < exclude-files.txt
find . -type f -print0 | xargs -0 shasum -a 256 | grep -v -P "${exclude_files}" > ~/out.txt
文件内容exclude-files.txt
:
Icon\\r
.DS_Store
--- empty line ---
该文件Icon\r
是用于更改文件夹图标的特殊文件,其名称包含CR
. (我在 Mac OS X 10.7.4 上)