[英]Find file in list of directories piped from output of other command
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
. 因此,我想在从命令
dpkg -L package_name
返回的每个目录上find dir -name "filename" > find.out
。
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. 我认为管道和
xargs
很有用,但我不知道如何告诉xargs
是find
命令中查找的目录。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.