[英]Shell Script: Copying files with wildcard (*) to from one folder to another folder
A very simple question but bothers me.一个非常简单的问题,但困扰着我。 I want to copy all files in one folder to another folder in a shell script.我想将一个文件夹中的所有文件复制到 shell 脚本中的另一个文件夹中。 Like this:像这样:
#!/bin/sh
cp data/* /tmp/data
But got error: zsh:1: no matches found: data/*
但得到error: zsh:1: no matches found: data/*
Reading various posts on stackoverflow, like here: Copying files with wildcard (*) to a folder in a bash script - why isn't it working?阅读有关 stackoverflow 的各种帖子,例如: 将带有通配符 (*) 的文件复制到 bash 脚本中的文件夹 - 为什么它不起作用? I have tried:我试过:
cp "data"/* /tmp/data
Error: zsh:1: no matches found: data/*
cp -r data /tmp/data
Error cp: cannot stat `data': No such file or directory
I could verify data folder contains files, and I'm in the parent directory data folder.我可以验证数据文件夹包含文件,并且我在父目录数据文件夹中。 If I do ls data
in the script, the contents of it are correctly printed.如果我在脚本中执行ls data
,它的内容将被正确打印。
Could anyone help?有人可以帮忙吗? I'm using zsh.我正在使用 zsh。
I think the command you are looking for might be cp -r data /tmp/
.我认为您正在寻找的命令可能是cp -r data /tmp/
。 It will create the data
directory in /tmp/
.它将在/tmp/
创建data
目录。
$ cp "data/*" /tmp/data
它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.