【问题标题】:finding and copying all files beginning with strings which are read from a text file查找并复制所有以从文本文件中读取的字符串开头的文件
【发布时间】:2017-04-23 00:57:57
【问题描述】:

我有一个文本文件,我将从中读取行。 对于每一行,我想在特定文件夹中查找以该行开头的文件并将这些文件复制到目标位置

假设我的文本文件 anmely file.txt 是这样的:

abc
def
xyz

所以,我想在源文件夹中找到以abc、def 等开头的文件,并将所有这些文件复制到目标文件夹中。

我写了以下命令,但它不起作用:

while read line
do
cp /srcdirectory/$line* /destdirectory/ < file.txt
done

【问题讨论】:

    标签: unix while-loop


    【解决方案1】:

    你很亲密:

    while read line
    do 
        ls "$line"*    # replace me with cp 
    done < file.txt  # then whole "while" statement executes reading from file.txt
    

    【讨论】:

      猜你喜欢
      • 2011-05-01
      • 2013-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 2017-06-01
      相关资源
      最近更新 更多