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 ...)
There's no option for that in updatedb.conf
. You'll have to arrange to pass options to updatedb
manually.
With updatedb from GNU findutils, pass --localpaths
.
updatedb --localpaths '/ /media/win_c/somewhere/Music /media/win_c/somewhere/Photos'
With updatedb from mlocate, there doesn't appear a way to specify multiple roots or exclude a directory from pruning, so I think you're stuck with one database per directory. Set the environment variable LOCATE_PATH
to the list of databases:
updatedb --output ~/.media.mlocate.db --database-root /media/win_c/somewhere --prunepaths '/media/win_c/somewhere/Videos'
export LOCATE_PATH="$LOCATE_PATH:$HOME/.media.mlocate.db"
Best Answer
If you are unable to find the file with the below command then try
updatedb
for updating db used by locate command.or
find command can also do this
find / -path */foot/bar*
find /
will search the whole system starting from/