我有一个查找表达式来查找node_modules
目录。部分结果是父 node_modules
目录中的 node_modules
目录。
我只对查找最顶层的 node_modules
目录并对其执行操作感兴趣,即添加 .metadata_never_index
文件,以便 Spotlight (macOS) 不会' t 对其进行索引。
我正在努力寻找解决这个问题的解决方案;可以找到为我做这个,或者我需要手动计算它(也许通过字符串操作)?
作为奖励,如果可能的话,我想忽略所有已包含 .metadata_never_index
文件的文件夹。
编辑:一些上下文;这将作为 cron 作业运行,并定期在我的 ~/Sites
目录中查找 node_modules
,即多个顶级项目。
最佳答案
经过一番搜索,我在 SuperUser 上找到了解决方案.
总结 Paxali 的回答:
find /home/code -type d -name ".git" | grep -v '\.git/'
In english: find me all directories named ".git" and filter out any occurences in the resultlist which contain ".git/" (dot git slash).
除了我的情况外,我使用了 node_modules/
而不是 .git/
。
我的工作代码:
find -f ~/Sites . -name node_modules | grep -v 'node_modules/' | while read fname; do
touch $fname/.metadata_never_index
done
关于bash - 将 `find` 的结果减少到顶级结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44745713/