I'm generating ctags using something like the following line

find -iname '*.[hc]' -exec ctags -a --sort=no {} +

The result is that tags are not sorted. For that I'm using

sort -u -o tags tags

What I'm curious about, is it possible to do all of this in find? In other words, can I instruct find to use --sort=no for all but last invocation of ctags, when it would use --sort=yes?

The current way is sufficient (and ctags internally calls sort -u -o $TAGFILE $TAGFILE anyway) but I'm curious if this is possible.

  • Your current line should only invoke ctags once. – jordanm Aug 4 '15 at 13:57
  • 4
    I do not agree. pubs.opengroup.org/onlinepubs/9699919799/utilities/… : " The size of any set of two or more pathnames shall be limited such that execution of the utility does not cause the system's {ARG_MAX} limit to be exceeded. ". On my reposiroty (20 year old system with multiple milions of LoC) ctags is executed 16 times – graywolf Aug 4 '15 at 14:02

I'm pretty sure find can't do it. If instead of -exec {} you use the classic print-to-xargs (and the filenames don't contain characters special to shell like space, dollarsign, or quotes, or you go to the trouble of protecting them) you can identify and "correct" the last group=line:

find -iname pattern | xargs echo ctags -a --sort=no | sed '$s/sort=no/sort=yes/' | sh 

But as you implicitly ask, why bother when you can just run the sort?

  • heh I like it :) why bother? curiosity, was just interested if it's possible to do something like this. so, thanks :) – graywolf Aug 5 '15 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.