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?

3
  • 1
    Sadly the answer seems to be no.
    – Nifle
    Dec 8, 2014 at 13:27
  • 5
    It seems every couple of months I google this and get back to this page. Jun 15, 2016 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, 2016 at 19:54

1 Answer 1

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .