我正在尝试使用配置文件提供的数组来排除find. 数组的一个简单示例如下所示:
excludedDirList2[0]='*.'
excludedDirList2[1]='node_modules'
Run Code Online (Sandbox Code Playgroud)
我一直在摆弄-prune和! -path选项,但我无法找到一种动态读取数组、生成find并使其实际工作的方法。
可以运行但不能动态读取数组的命令示例
find $dir -type f -name "hidden.txt" ! -path "${excludedDirList[1]}" ! -path "${excludedDirList[0]}"
Run Code Online (Sandbox Code Playgroud)
如果有效,只需在数组的每个元素前面添加 和 并将其传递!给.-pathfind
excludedDirList2=('*.' 'node_modules')
findargs=()
for i in "${excludedDirList2[@]}"; do
findargs+=('!' '-path' "$i")
done
find "$dir" -type f -name "hidden.txt" "${findargs[@]}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
891 次 |
| 最近记录: |