我是使用终端的新手,我在这里找到了一篇文章,其中包含以下代码,该代码允许我将多个目录压缩到单独的 zip 文件中,但我只让它工作一次。代码是这样的:
for i in */; do zip ‐r "${i%/}.zip" "$i"; done
但现在当我使用它时,我会收到以下错误:
zip warning: name not matched:
当我检查文件夹时,它会创建一个-r.zip
文件。
答案1
看起来 zip 首先需要 zip 文件:
for i in */; do zip "${i%/}.zip" -r "$i" ; done
答案2
如果您是终端新手,那么您可能还没有了解令人畏惧但有用的手册页世界:D
如果您man zip
在命令行中执行此操作,则 zip 的预期用法如下:
"Normally when an input pattern
does not match a file the "name not matched" warning is issued
"
If zip is not able to read a file, it issues a warning but continues.
See the -MM option below for more on how zip handles patterns that are
not matched and files that are not readable. If some files were
skipped, a warning is issued at the end of the zip operation noting how
many files were read and how many skipped."
我首先将您的 zip 命令替换为 echo“${i%/}”,然后查看您的输出是什么。某个文件夹导致问题,您无法访问它或者它的名称不正确。由于您只是查看一个目录中的文件夹,因此您可以使用它find . -type d -readable
与您想要访问的目录进行比较,以查看是否存在您实际上无权读取的文件夹。
相关 Unix Stack Exchange 答案:
https://stackoverflow.com/questions/20529851/zip-command-not-working