7-Zip command line add only specific file to archive

7-zipcommand line

There's lots of questions asking how to add only files with a particular file extension to an archive, but to my great surprise it seems like no one wants to add a single file to an archive.

How do I add a single specific file to an archive with the 7-Zip command line?

Best Answer

The approach would be the same, just the bit at the end would be a little different.

So for a particular file extension you would do this:

7z a -t7z archive.7z *.txt 

You have just added all the .txt files.

But let's say you want to add a pdf and a doc to that, you would do this:

7z a -t7z archive.7z file.pdf file2.doc

Note: This won't create a new archive.7z, rather it will just add file.pdf and file2.doc to the archive.7z you created earlier.