Finding a specific file type with ack
Use --type for this. To find python files like:
ack --type=python searchthis
List all supported types with
ack --help=types
If you want to create your own type, add something like this to ~ / .ackrc:
--type-add=custom:ext:rb
--type-set
Then you can use --type = custom with ack to just look for the .rb file.
source to share
The short answer is:
ack blah --css
Long answer:
You can add file types to your search to teach Ack to view only those files. For example, let's link the css and sass extensions with the short name "stylesheets":
ack --type-add=stylesheets:ext:css,sass
Now that you've taught Ack how to search for the types of files you want to associate with the short name "stylesheets", you can ask Ack to use that short name with:
ack --type-add=stylesheets:ext:css,sass --type=stylesheets blah
Or in a short way:
ack --type-add=stylesheets:ext:css,sass --stylesheets blah
Even in short, it's a lot to type for search and for this reason such commands are better used in a config file, for example ~/.ackrc
, but I prefer to use them with an alias in mine ~/.bashrc
.
But why does it default to --type=css
or --css
? Because Ack has default file name groups that you can ack --dump
use ack --dump
.
Using Ack version: 2.24
source to share