Add files from "bash find" to 7z archive

I did quite a bit of searching before asking this! (Even so I’m expecting to have a duplicate pointed out).

So I collect a bunch of files, e.g.:

find . -name "2020-*" 

… is there some way to "pipe" all these files into a .7z archive? (NB I realise "pipe" may not be the right word as the operation I want is in fact a file-copy operation).

I’ve tried things like:

find . -name "2020-*" | 7z a -p pumple.7z

… this gives me ">" on the next line, as though it’s expecting some console input.

So does the following:

 find . -name "2020-* > 7z a -p pumple.7z
Asked By: mike rodent


You need to provide the file names as arguments to 7z:

find . -name '2020-*' -exec 7z a -p pumple.7z {} +

This tells find to look for files (of any type) whose name matches 2020-*, and when it finds such files, run 7z a -p pumple.7z followed by the names of the files. The {} is the placeholder for the file names, and + tells find to run the command with as many file names as possible in one go.

Answered By: Stephen Kitt
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.