When I search e.g. my home directory with ack (or grep), I normally want to know where I set a specific option.

Since most config files are really close to ~ it would considerably speed up ack if I could search breadth-first. Is this possible?

  • 1
    Sadly the answer seems to be no. – Nifle Dec 8 '14 at 13:27
  • 4
    It seems every couple of months I google this and get back to this page. – Gregory Nisbet Jun 15 '16 at 18:32
  • 2
    @GregoryNisbet My „solution“ has been to switch to ag, which is about 5–10 times faster than ack and provides no drawbacks. Combined with switching to SSD I haven’t had the problem since. – Profpatsch Jun 21 '16 at 19:54

I don't know ack but with tools such as grep I typically use:

( find . -maxdepth 1 -print ; find . -mindepth 2 -print ) | xargs -n 50 -exec grep TXT

The part between ( and ) ensures that first the files at level 1 are listed and after that those at 2 and deeper (you can vary). xargs feeds the file names per 50 to grep.

Of course it depends on which variant of find is available on your platform. If running something from 30 years ago, you will need to use something like sorting on the number of forward slashes.

  • MMV (Archlinux): grep: ./.macromedia/Flash_Player/#SharedObjects/Q2GSRK6Y/www.mixcloud.com/media: Is a directory – xtian Aug 4 '17 at 17:08
  • If you're not going to use -print0 to find, at least do find . -maxdepth 1 -exec grep {} +;. mywiki.wooledge.org/BashFAQ/020 – lmat - Reinstate Monica Apr 10 '18 at 19:44

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.