将当前目录下的所有HTML文件压缩在一起

时间:2013-07-01 10:23:35

标签: linux command-line

我希望在当前目录下递归地压缩* .html文件。

我当前的命令是:

zip all-html-files.zip *.html 

但这不会递归地起作用。似乎也没有添加-r选项。有人可以提供建议吗?我想压缩当前目录下的所有html文件,包括子目录下的那些文件,但只压缩HTML文件,而不是压缩文件夹。

谢谢!

3 个答案:

答案 0 :(得分:7)

这个怎么样?

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

答案 1 :(得分: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).

答案 2 :(得分:1)

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