Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ag aka the_silver_search to search for directories only?

Tags:

ag

I like to search for directories only, and the option ag --list-file-types is not helpful with that. The reason to stick to ag is the possibility to pick a file with --path-to-ignore containing patterns to ignore.

An equivalent command would be fd --type d.

like image 348
F. Röder Avatar asked Sep 11 '25 22:09

F. Röder


1 Answers

Use the -G argument, and specify a directory name.

For example, if you wanted to search for the word "foobar" in only your Downloads directory:

ag -G "Downloads" foobar

To search inside a nested directory:

ag -G "Downloads/some_directory" foobar 

To search in multiple directories:

ag -G "Downloads|Documents" foobar
like image 180
gregory Avatar answered Sep 13 '25 20:09

gregory