Yes, you can use xargs
for this.
For example a simple:
$ locate commands.cfg | xargs grep check_dns
(When grep
sees multiple files it searches in each one and enables filename printing along matches.)
Or you can explicitly enable filename printing via:
$ locate commands.cfg | xargs grep -H check_dns
(Just in case one grep
is called only with 1 argument by xargs
)
For programs that only accept one filename argument (unlike grep
) you can restrict the number of supplied arguments like this:
$ locate commands.cfg | xargs -n1 grep check_dns
That does not print the names of files where matched lines are from.
The result is equivalent to:
$ locate commands.cfg | xargs grep -h check_dns
With a modern locate/xargs you can also protect against whitespace issues:
$ locate -0 commands.cfg | xargs -0 grep -H check_dns
(By default whitespace separates input of xargs
- which is of course a problem when your filenames contain whitespace ...)
This seems to do the job.
locate -ir '^/home/jack/\([^.][^/]\+/\)\+My[^/]*$'
Quotes from manual:
-i, --ignore-case Ignore case distinctions when matching patterns.
-r, --regexp REGEXP Search for a basic regexp REGEXP. No PATTERNs are allowed if this option is used, but this option can be specified
multiple times.
Best Answer
That depends on the
locate
you use. There are a couple of implementations, with identical executable names, but various package names: locate, slocate, mlocate, rlocate.Usually they all have
-i
and/or--ignore-case
switch. Consult yourlocate
's man page for the exact syntax.Also usually they have no configuration file, so if you want to set the case-insensitiveness persistently, set an alias in your .bashrc (or similar) file:
alias locate='locate -i'
.