Reputation: 7044
I need to find location of a file. I don't want to search entire system, and I know that the file I am looking for is in a directory related to a certain package.
So I would like to do find dir -name "filename" > find.out
on every dir that is returned from the command dpkg -L package_name
.
How do I do that? I think piping and xargs
would be useful but I don't know how to tell xargs
to be the dir to lookup in the find
command.
Upvotes: 1
Views: 67
Reputation: 75488
You can do:
#!/bin/bash
readarray -t DIRS < <(exec dpkg -L package_name) ## Store file list to an array.
find "${DIRS[@]}" -name "filename" > find.out ## Search all at once.
Run with
bash script.sh
Or perhaps do it with just one line anyway:
readarray -t DIRS < <(exec dpkg -L package_name); find "${DIRS[@]}" -name "filename" > find.out
Upvotes: 2