简体   繁体   English

Shell 脚本:将带有通配符 (*) 的文件从一个文件夹复制到另一个文件夹

[英]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.

相关问题 使用Shell脚本将文件从一个文件夹复制到另一个文件夹 - Copying files from one folder to another using a shell script Unix Shell脚本,用于将文件从一个文件夹复制到另一个文件夹 - Unix Shell scripting for copying file from one folder to another Shell命令,用于将一个文件夹的内容复制到另一个文件夹 - Shell command for copying the contents of one folder to another 从另一个文件夹linux shell中删除一个文件夹中的文件 - removing files which are in one folder from another folder linux shell UNIX Shell将文件从一个文件夹移动到另一个文件夹 - UNIX shell to move files from one folder to another folder 在Shell脚本中移动文件并将文件同时复制到同一文件夹 - Moving files in shell script and copying files to the same folder at the same time Shell脚本重命名并将文件从一个文件夹移动到另一个文件夹 - Shell script rename and move files from one folder to the other [Unix] [Shell脚本]将所有文件从一个文件夹复制到另一个文件夹 - [Unix][Shell Script] Copy all files from one folder to the other Shell 脚本,用于将特定文件从 csv 复制到具有相同文件夹层次结构的另一个目录 - Shell script for copying the specific file from csv to another directory with same folder hierarchy structure 如何每天从文件夹中获取文件,然后使用Shell脚本将其存储在另一个文件夹中? - How to get the files from a folder everyday and store it in another folder using shell script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM