4

I am looking to zip together *.html files recursively under the current directory.

My current command is:

zip all-html-files.zip *.html 

But this doesn't work recursively. Nor does adding the -r option it seems. Can anybody advise? I want to zip all html files under the current directory, including those underneath subdirectories, but zip the HTML files only, not their file folders.

Thanks!

4

3 回答 3

8

那这个呢?

find /your/path/ -type f -name "*.html" | xargs zip all_html_files.zip

查找.html目录下的所有文件/your/path(将其更改为您的)。然后,将结果通过管道传输到xargs,从而创建 zip 文件。

要垃圾路径,请添加-j选项:

find /your/path/ -type f -name "*.html" | xargs zip -j all_html_files.zip
于 2013-07-01T10:26:50.880 回答
1

尝试

find . -type f -name "*.html" | xargs zip all-html-files

你也可以说

find . -type f -name "*.html" | zip all-html-files -@

如果您不想保留目录结构,请指定-j选项:

find . -type f -name "*.html" | zip -j all-html-files -@

man zip说:

   -@ 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).

   -j
   --junk-paths
          Store just the name of a saved file (junk the path), and do  not
          store  directory names. By default, zip will store the full path
          (relative to the current directory).
于 2013-07-01T10:27:38.473 回答
1
find . -name "*.html" -print | zip all-html-files.zip -@
于 2013-07-01T10:28:13.117 回答