我有一个 find 命令,我想对其进行排序,以便某些目录的条目最后排序。原因是这个列表要传递给 etags 以创建标签表,并且我希望某些第三方工具目录位于我主动编辑的所有代码之后。
有人可以建议一种简单的方法来对列表进行排序作为对我的 makefile 规则的更改吗?这是当前规则:
tags:
rm -f ../TAGS
find .. \( -not -regex '.*include/.*' \) \
-a \( -name '*.h' -o -name '*.hh' -o -name '*.y' \
-o -name '*.l' -o -name '*.cc' -o -name '*.cpp' \
-o -name '*.c' -o -name '*.inl' \) \
| xargs etags -o ../TAGS --append
例如,以“../flexlm/”或“../src/librsync”开头的条目应位于与这些模式之一不匹配的条目之后。
最佳答案
将多个 find
命令放入大括号 block 中,并将其通过管道传输到 xargs
中:
# the single quotes take care of the escaping
pattern='( -not -regex ".*include/.*" )
-a ( -name "*.h" -o -name "*.hh" -o -name "*.y"
-o -name "*.l" -o -name "*.cc" -o -name "*.cpp"
-o -name "*.c" -o -name "*.inl" )'
{
find ! -path "../flexlm/*" ! -path "../src/librsync/*" $pattern
find -path "../flexlm/*" $pattern
find -path "../src/librsync/*" $pattern
} | xargs etags -o ../TAGS --append
关于bash - 如何对查找结果进行排序,以使以一组模式之一开头的路径排在最后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3697457/