【问题标题】:Find file in list of directories piped from output of other command在从其他命令的输出管道传输的目录列表中查找文件
【发布时间】:2014-08-30 23:17:29
【问题描述】:

我需要找到一个文件的位置。我不想搜索整个系统,而且我知道我要查找的文件在与某个包相关的目录中。

所以我想对命令dpkg -L package_name返回的每个目录执行find dir -name "filename" > find.out

我该怎么做?我认为管道和xargs 会很有用,但我不知道如何告诉xargs 成为在find 命令中查找的目录。

【问题讨论】:

    标签: bash unix find pipe xargs


    【解决方案1】:
    find $(dpkg -L package_name) -name "filename" > find.out
    

    【讨论】:

      【解决方案2】:

      你可以这样做:

      #!/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.
      

      运行

      bash script.sh
      

      或者也许只用一行来做:

      readarray -t DIRS < <(exec dpkg -L package_name); find "${DIRS[@]}" -name "filename" > find.out
      

      【讨论】:

        猜你喜欢
        • 2021-10-24
        • 2020-10-08
        • 2018-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-28
        • 2014-05-06
        • 2019-01-24
        相关资源
        最近更新 更多