我想在一个目录及其子目录中找到所有文件,但不包括任何设置文件和任何位于设置或依赖目录中的文件。
例如,我希望从结果中排除整个目录,如.git、.idea 和 node_modules,以及像.DS_Store 和 config.codekit 这样的文件,但我想包括.gitignore。
我所需的是类似以下 Git 命令的结果,但包括任何未跟踪的文件,并且可以轻松安全地操作(例如更改权限)。
例如,我希望从结果中排除整个目录,如.git、.idea 和 node_modules,以及像.DS_Store 和 config.codekit 这样的文件,但我想包括.gitignore。
我所需的是类似以下 Git 命令的结果,但包括任何未跟踪的文件,并且可以轻松安全地操作(例如更改权限)。
git ls-tree -r master --name-only
以下是我目前的代码,虽然有些臃肿,但它似乎基本实现了我的目标,除了忽略 .gitignore 文件:
find . -type f -not -name ".*" -not -name config.codekit -not -path "./.*" -not -path "./node_modules/*"
我尝试过使用-prune,但并没有取得太大的成功。
在Bash中,是否有一种指定排除项的例外情况的方法,比如说排除所有与此模式匹配的内容,除了这个或这些?
顺便说一下,我目前正在使用OS X,但我也使用Ubuntu,并计划在Windows 10周年更新普及后尝试在Windows上使用Ubuntu,因此理想情况下,我希望有一个可在所有这些操作系统上运行的命令。
提前感谢您提供任何解决方案、见解或优化!
更新
感谢gniourf-gniourf的帮助,我已经修改了我的命令。这似乎实现了我想要的功能:
find . -type f \( \! -name ".*" \! -name config.codekit \! -path "./.*" \! -path "./node_modules/*" -o -name .gitignore \)
find . -type f \( \! -name ".*" \! -name config.codekit \! -path "./.*" \! -path "./node_modules/*" -o -name .gitignore \)
- Brian Sextonfind . -type f \! -name ".*" \! -name config.codekit \! -path "./.*" \! -path "./node_modules/*" -o -name .gitignore
- Brian Sexton-o
的存在,-type f
谓词不会应用于-name .gitignore
谓词,因此您还将匹配.gitignore
_目录_。 - gniourf_gniourf