Arrays 如何将文件列表复制到目录?

Arrays 如何将文件列表复制到目录?,arrays,bash,shell,Arrays,Bash,Shell,当我将$(pwd)分配给变量时,我无法将其作为路径传递给cp: files=$(find /mnt/eee/ttt/*) pwd /mnt/xxx/yyy path=$(pwd) echo $path mnt xxx yyy 当我将path与cp一起使用时 $files | cp $a cp: target ‘xxx’ is not a directory cp不会从stdin读取文件名,因此将列表管道化到cp是徒劳的。您是否将cp与cpio混淆了?它们是不同的程序 您需要运行cp{

当我将
$(pwd)
分配给变量时,我无法将其作为路径传递给
cp

files=$(find /mnt/eee/ttt/*)
pwd 
/mnt/xxx/yyy

path=$(pwd)

echo $path 
mnt xxx yyy
当我将path与cp一起使用时

$files | cp $a
cp: target ‘xxx’ is not a directory

cp
不会从stdin读取文件名,因此将列表管道化到
cp
是徒劳的。您是否将
cp
cpio
混淆了?它们是不同的程序

您需要运行
cp{list of files}{destination directory}
,例如

cp $files $path
如果要将所有文件复制到当前工作目录,应使用
以简化和可读性(
表示当前工作目录):


请务必使用
man-cp
阅读
cp
手册页,您将很快成为shell向导:-)

您可以使用以下代码:

cp $file1 && file2 && 

奇怪的是,为什么在echo输出的
mnt xxx yyy
之间没有
/
?变量
$a
是什么?
cp
不能从标准输入读取。这是如何工作的
files+=$(find*)
newdir=$(mktemp XXXXX-d)
因为我想要的是
$files | parallel cp{}$newdir
并将$newdir作为目标传递给parallel cp命令?不,您不需要并行cp。你就抄吧。您可以运行
cp$(查找…)/name/of/destination/directory
cp $file1 && file2 &&