zip - 忽略大量特定文件,而不会超出命令行范围

zip - 忽略大量特定文件,而不会超出命令行范围

我正在尝试压缩一个目录,但我有一个需要忽略的特定文件列表。该列表是使用脚本生成的,并且相当长,因此当我将它们传递给命令时,zip我收到一条错误消息,指出命令行太长。

我基本上需要这个问题中提出的功能 -压缩文件夹中某些文件的大型列表时参数列表太长- 但可以选择-x忽略文件而不是添加它们。

这些文件位于各个子目录中,并且不遵循特定的命名约定,因此没有明确的模式可以忽略它们而不单独指定它们。

有什么办法可以做到这一点吗?

答案1

您可以(按照联机帮助页中的建议)将列表放入文件中,而不是使用列表的位置参数:

   -x files
   --exclude files
          Explicitly exclude the specified files, as in:

                 zip -r foo foo -x \*.o

          which  will include the contents of foo in foo.zip while exclud‐
          ing all the files that end in  .o.   The  backslash  avoids  the
          shell  filename  substitution, so that the name matching is per‐
          formed by zip at all directory levels.

          Also possible:

                 zip -r foo foo [email protected]

          which will include the contents of foo in foo.zip while  exclud‐
          ing   all  the  files  that  match  the  patterns  in  the  file
          exclude.lst.

相关内容