Answers:
这对我有用:
zip -r mydir.zip mydir -x "*/.*"
@Joe Internet,@ Dariusz:正常的外壳模式将无法正常工作,因为zip内部匹配完整的路径名和文件名(如zip手册中解释的...;))
以下方法适用于这种类型的目录树:
$ tree .
.
├── adir1
│ ├── afile1
│ ├── afile2
│ ├── afile3
│ └── afile4.txt
├── adir2
│ ├── afile1
│ ├── afile2
│ ├── afile3
│ └── afile4.txt
├── adir3
│ ├── afile1
│ ├── afile2
│ ├── afile3
│ └── afile4.txt
├── afile1
├── afile2
├── afile3
├── foo.test
这是适用于这种情况的解决方案(我认为是更一般的情况)。
$ find . -type f -not -path '*/\.*' -exec zip -r test.zip {} +
$ find . -type f -not -path '*/\.*' -exec zip -r test.zip {} +
updating: adir1/afile1 (stored 0%)
updating: adir1/afile1.zip (stored 0%)
updating: adir1/afile2 (stored 0%)
updating: adir1/afile3 (stored 0%)
updating: adir1/afile4.txt (stored 0%)
updating: adir2/afile1 (stored 0%)
updating: adir2/afile2 (stored 0%)
updating: adir2/afile3 (stored 0%)
updating: adir2/afile4.txt (stored 0%)
updating: adir3/afile1 (stored 0%)
updating: adir3/afile2 (stored 0%)
updating: adir3/afile3 (stored 0%)
updating: adir3/afile4.txt (stored 0%)
updating: afile1 (stored 0%)
updating: afile2 (stored 0%)
updating: afile3 (stored 0%)
updating: foo.test (deflated 87%)
更短,并且利用了globbing的功能:
zip -r mydir.zip mydir/*
(。文件不包含在*通配符中)
请注意,目录“ mydir /”可能不包含在生成的zip文件中的文件路径中,因此这将稍微改变输出。结果,您可能必须更改提取过程。