我如何搜索文件并将其压缩在一个zip文件中

时间:2023-01-15 10:22:53

I tried to search files and zip them with the following commmand

我尝试使用以下命令搜索文件并压缩它们

find . regexpression -exec zip {} \;

however it is not working. How can i do this?

但它不起作用。我怎样才能做到这一点?

3 个解决方案

#1


48  

The command you use will run zip on each file separately, try this:

您使用的命令将分别在每个文件上运行zip,请尝试以下操作:

find . -name <name> -print | zip name.zip -@

The -@ tells zip to read files from the input, from man zip(1):

- @告诉zip从输入中读取文件,来自man zip(1):

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

- @文件列表。如果文件列表指定为 - @ [Not on MacOS],则zip从标准输入而不是命令行获取输入文件列表。

#2


12  

You can also provide the names as the result of your find command:

您还可以提供find命令的结果名称:

zip name.zip `find . -name <name> -print`

This is a feature of the shell you are using. You can search for "backticks" to determine how your shell handles this.

这是您正在使用的shell的一个功能。您可以搜索“反引号”以确定shell如何处理此问题。

#3


7  

Your response is close, but this might work better:

您的回复很接近,但这可能会更好:

find -regex 'regex' -exec zip filname.zip {} +

That will put all the matching files in one zip file called filename.zip. You don't have to worry about special characters in the filename (like a line break), which you would if you piped the results.

这将把所有匹配的文件放在一个名为filename.zip的zip文件中。您不必担心文件名中的特殊字符(如换行符),如果您输出结果,则可以使用。

#1


48  

The command you use will run zip on each file separately, try this:

您使用的命令将分别在每个文件上运行zip,请尝试以下操作:

find . -name <name> -print | zip name.zip -@

The -@ tells zip to read files from the input, from man zip(1):

- @告诉zip从输入中读取文件,来自man zip(1):

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

- @文件列表。如果文件列表指定为 - @ [Not on MacOS],则zip从标准输入而不是命令行获取输入文件列表。

#2


12  

You can also provide the names as the result of your find command:

您还可以提供find命令的结果名称:

zip name.zip `find . -name <name> -print`

This is a feature of the shell you are using. You can search for "backticks" to determine how your shell handles this.

这是您正在使用的shell的一个功能。您可以搜索“反引号”以确定shell如何处理此问题。

#3


7  

Your response is close, but this might work better:

您的回复很接近,但这可能会更好:

find -regex 'regex' -exec zip filname.zip {} +

That will put all the matching files in one zip file called filename.zip. You don't have to worry about special characters in the filename (like a line break), which you would if you piped the results.

这将把所有匹配的文件放在一个名为filename.zip的zip文件中。您不必担心文件名中的特殊字符(如换行符),如果您输出结果,则可以使用。