12

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?

Profpatsch
  • 427
  • 4
  • 13
  • 1
    Sadly the answer seems to be no. – Nifle Dec 08 '14 at 13:27
  • 5
    It seems every couple of months I google this and get back to this page. – Greg 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

1 Answers1

3

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.

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