同时排除某个目录(查找命令)-BASH [英] Exclude a certain directory while (find command) - BASH
本文介绍了同时排除某个目录(查找命令)-BASH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此Bash脚本遍历/app目录中的每个文件.
This Bash script goes through every file in /app directory.
这是树层次结构
/app
_/a
-/b
-/test/unittest/python/test.py
问题是,我不想执行皮棉步骤.如何排除测试目录?
Problem is,,, I don't want to execute lint step. How do I exclude test directory?
...
for file in $(find /app -name '*.py'); do
filename=$(basename $file)
if [[ $filename != "__init__.py" ]] ; then
echo "$file"
pylint "${file}" --rcfile="${lint_path}" || exit 1
fi
done
这是一种解决问题的方法,不确定是否正确.不起作用!
This is a way to solve the problem not sure if it's right. not working!
$(find /app -name '*.py' -not -path '*test*')
推荐答案
使用 -prune
选项可以防止进入 test
目录.
Use the -prune
option to prevent descending into the test
directory.
您还可以在 find
中排除 __ init __.py
,因此您无需使用 if
进行测试.
You can also exclude __init__.py
in find
so you don't need to test that with if
.
$(find /app -type d -name test -prune -o -type f -name '*.py' ! -name '__init__.py' -print)
这篇关于同时排除某个目录(查找命令)-BASH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文