如果我理解正确,这是将 a 与 b 进行比较的可能解决方案:
mkdir a b ; touch a/HouseFile.txt a/ChairFile.txt a/CouchFile.txt a/SomeFile.txt b/House.txt b/Chair.txt b/Couch.txt b/Sofa.txt
for file in a/*(.); do [[ ! -f b/${${file##*/}:fs@File@} ]] && echo $file ; done
输出:
a/SomeFile.txt
我不清楚的是:差异模式是严格的“文件”还是任意字符串?
编辑:前一个是针对 zsh 的。这是 bash 的一个:
find a -type f -maxdepth 1 | while read file; do
check=$(echo $file | sed -r -e 's@(.*)/(.*)@\2@' -e "s@File@@") ;
[[ ! -f b/${check} ]] && echo $file
done
使用参数扩展而不是sed
:
find a -type f -maxdepth 1 | while read file; do
check=${file/%File.txt/.txt} #end of file name changed
check=${check/#*\//} #delete path before the first slash
[[ ! -f b/${check} ]] && echo $file
done