【问题标题】:Using Find to find files with similar names to a list defined in a file. Possible?使用 Find 查找与文件中定义的列表具有相似名称的文件。可能的?
【发布时间】:2018-06-04 18:44:32
【问题描述】:

是否可以在“查找”命令中使用包含文件名列表的文件作为参数?

例如,

list.txt:

car*
test*
owl*

我希望 find 命令将每个条目用作其“-name”选项的一部分。

不知道该怎么做,或者是否可能?

【问题讨论】:

    标签: linux shell find


    【解决方案1】:

    使用bash,您可以先在数组中构建模式列表,然后运行find

    arr=()
    while read -r arg; do
       arr+=(-name "$arg" -o)
    done < list.txt
    
    # run find command with pattern coming from array
    find . \( "${arr[@]}" -name '' \)
    

    【讨论】:

      【解决方案2】:

      Find 接受多个-name。对OR 使用-o 选项

      find . -name "car*" -o -name "test*" -o -name "owl*"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-11
        • 1970-01-01
        • 1970-01-01
        • 2011-01-11
        • 2022-11-25
        • 2015-11-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多