Linux:将txt文件中列出的文件从目录(带子目录)复制到指定的文件夹

时间:2011-01-12 00:07:31

标签: linux batch-file copy-paste

我有一个txt文件,其中只包含文件名。即“999000 999008 999021”等。它们对应于扩展名为* .source I.e的文件。 999000.source 999008.source 999021.source。这些文件存在于主目录下的不同子目录中。如何使用Linux中的命令将txt文件中列出的文件复制到另一个指定的文件夹?

谢谢, 杰克

1 个答案:

答案 0 :(得分:2)

如果文件名中没有空格:

(for fn in $(cat filenames.txt); do
    find "$master_dir" -type f -name "$fn.source"
done) |tar -cT - |(cd "$new_dir" && tar x)