Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can ack find files based on filename only?

Tags:

filenames

ack

Using ack (sometimes packaged as ack-grep) I know that I can find paths that contain a specific string by doing:
ack -g somestring

But what if I only want files which have "somestring" in their filenames?

like image 633
Suan Avatar asked Oct 08 '11 18:10

Suan


People also ask

What does Ack command do?

Ack is designed as a replacement for 99% of the uses of grep. Ack searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN . By default, ack prints the matching lines.

What is ACK grep?

Ack is a search tool like just grep, but it's optimized for searching in source code trees. Ack does almost all that grep does, but it differs in the following ways. Ack was designed to: Search directories recursively by default. Easily exclude certain file types or only search for certain file types.


2 Answers

I agree find is the way to go, but you could also easily do it with ack:

ack -f | ack "string" 

Here, "ack -f" recursively lists all the files it would search; pipe that to the second ack command to search through that. ack -f does have the advantage of skipping over binaries and directories even without any more arguments; often, then a "find" command could be replaced by a much shorter "ack" command.

like image 77
user2141650 Avatar answered Sep 18 '22 17:09

user2141650


You can use find utility. Something like this:

find /path/to/look/in -name '*somestring*' -print 

On some systems, if you omit the path, current directory is used. On other systems you can't omit it, just use . for current directory instead.

Also, read man find for many other options.

like image 20
dmedvinsky Avatar answered Sep 19 '22 17:09

dmedvinsky