Is it possible to find files only based on the file name?

Using ack (sometimes packaged as ack-grep), I know that I can find paths containing a specific string using:
ack -g somestring

But what if I only want files that have "somestring" in the file names?

+23
filenames ack
Oct 08 '11 at 18:26
source share
5 answers

You can use the find utility. Something like that:

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

On some systems, if you omit the path, the current directory is used. On other systems you cannot omit it, just use it . for the current directory.

Also, read man find for many other options.

+20
Oct 08 '11 at 18:33
source share

I agree that searching is the way to go, but you can also do it easily with ack:

 ack -f | ack "string" 

Here "ack -f" recursively lists all the files that it will look for; go to the second command to search. ack -f has the advantage of skipping binary files and directories even without any additional arguments; often, the find command can be replaced by a much shorter ack command.

+39
Mar 06 '13 at 20:31
source share

If you want to use ack to search all files with somestring in their base name, just add [^/]*$ in the regular expression, for example,

 ack -g somestring[^/]*$ 

Unfortunately, --color will show a match from somestring to the end of the file name; but you can do what you asked to use ack .

+3
Jul 27 '16 at 2:57
source share

I can not comment yet, otherwise I would add this to @dmedvinsky's answer above. You can combine your approach with @whaley's answer to another question to filter out .svn files:

 find /path/to/look/in -not -iwholename '*.svn*' -name '*somestring*' -print 
0
Mar 22 '14 at 18:53
source share

this works for me, ack -all "somestring", where as ack - all "somestring" will search for all files containing this string. ack "somestring" will only search for files with this string. if you want to add some type of file to search forever, like ruby ​​files, or you can create a .ackrc file in your home directory, add the line -type-add = ruby ​​= .haml, .rake, .rsel. Josh

-one
Apr 12 '12 at 19:29
source share



All Articles