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.
find $(dpkg -L package_name) -name "filename" > find.out
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.