我需要将 80,000 个文件压缩为多个 zip 文件。这是我使用的命令:
zip -s 200M photos_test/*
但是我收到以下错误:
-bash: /usr/bin/zip: Argument list too long
除了手动拆分文件夹文件外,我还能做些什么来解决这个问题?
谢谢
答案1
如果您想要整个目录,您只需使用开关-r
:
zip -r -s 200M myzip photos_test
但这将包括所有子目录photos_test
。
答案2
问题似乎出在“*”的扩展上。使用文件夹名称或“.”:
如果您想在 zip 中包含根文件夹:
zip -r my.zip folder_with_80k_files
如果你不想在 zip 中包含根文件夹:
cd folder_with_80k_files
zip -r my.zip .
答案3
find photos_test/ -mindepth 1 -maxdepth 1 | zip -@ -s 200M
答案4
ls photos_test | zip -s 200M -@ photos
-@
将导致 zip 从中读取文件列表标准输入|
将管道输出进入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). ⋮