Answers:
如果您需要整个目录,则只需使用-r
开关:
zip -r -s 200M myzip photos_test
那将包括所有的子目录photos_test
。
find photos_test/ -mindepth 1 -maxdepth 1 | zip -@ -s 200M
find . -mindepth 1 -maxdepth -name '*.json' | zip {YOURZIPFILENAME}.zip -@
如果您不需要拆分并且想要按扩展名选择文件,请使用此选项。
ls photos_test | zip -s 200M -@ photos
-@
将导致zip从stdin读取文件列表|
将管中的输出的ls
成输入的zip
命令man zip
:
USE ⋮ -@ file lists. If a file list is specified as -@ [Not on MacOS], zip takes the list of input files from standard input instead of from the command line. For example, zip -@ foo will store the files listed one per line on stdin in foo.zip. Under Unix, this option can be used to powerful effect in conjunction with the find (1) command. For example, to archive all the C source files in the current directory and its subdirectories: find . -name "*.[ch]" -print | zip source -@ (note that the pattern must be quoted to keep the shell from expanding it). ⋮
-bash: /usr/bin/zip: Argument list too long
可能导致以下情况:1-由于未使用-r
开关,2-由于归档文件过多。因此,在第一种情况下,@ Mat的答案是正确的,在第二种情况下,@ IgnacioVazquez-Abrams的答案是正确的。