how can i search for files and zip them in one zip file

前端 未结 3 620
走了就别回头了
走了就别回头了 2021-01-31 15:12

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

相关标签:
3条回答
  • 2021-01-31 16:00

    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.

    0 讨论(0)
  • 2021-01-31 16:01

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

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

    The -@ tells zip to read files from the input. From 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.

    0 讨论(0)
  • 2021-01-31 16:05

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

    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.

    0 讨论(0)
提交回复
热议问题