bash 在linux中将文件列表从一个位置复制到另一个位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26396415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy list of files from one location to another in linux
提问by Jake
I'm attempting to copy a partial list of files on a drive to a location on another drive. The list of files to copy is in a text file that I've attempted to supply to a bash script as well as some cp and xargs commands but to no avail. Below is the bash attempt.
我正在尝试将驱动器上的部分文件列表复制到另一个驱动器上的某个位置。要复制的文件列表位于我试图提供给 bash 脚本以及一些 cp 和 xargs 命令的文本文件中,但无济于事。下面是 bash 尝试。
#!/bin/bash
while read line
do
find . -iname "$line" -exec cp '{}' /my/destination/drive \;
done < file_list.txt
The text file reads as filenames with no extensions, like below
文本文件读取为没有扩展名的文件名,如下所示
my-file001
my-file002
my-file003
I've also tried xargs and pax with the below attempts, also to no avail.
我还尝试了以下尝试的 xargs 和 pax,也无济于事。
cat file_list.txt | xargs cp -t /my/destination/drive
and
和
find . -type f -exec pax -rws'|.*/||' < file_list.txt /my/destination/drive/ '{}' \;
This questioncame close but not quite. Any suggestions?
这个问题接近但不完全。有什么建议?
回答by iqstatic
This will just do the trick for you:
这只会为您解决问题:
cat file_list.txt | xargs -I {} cp {} /destination/dir/path