Is there any way to selectively prevent certain file types from compression in 7-zip, like in WinRAR?

I'm trying to compress a huge folder (many gigabytes), and I don't want the already-compressed files (e.g. ZIP files) to be re-compressed -- they should be stored without compression.

  • Is there a specific reason (saving every little bit of processing time possible, reading them without having to bundle the 7z binary or re-implement LZMA, etc.) that you want to do this? Generally speaking, most compression tools I've run into tend to be smart enough to automatically store things uncompressed if they find a file responds poorly to an attempt to compress it further.
    – ssokolow
    Sep 19, 2011 at 2:38
  • @ssokolow: It's been 4 years and I guess I never answered your question, but there can be other reasons such as minimizing damage from corruption and also making it easier to recover data in a disaster.
    – user541686
    Dec 17, 2015 at 11:52
  • Connected question: unix.stackexchange.com/questions/241898/… Jan 31, 2016 at 22:54

3 Answers 3


Yes, it is possible to have different compression methods for different files within the same 7-Zip archive.

Use the command line version of 7-Zip with the -m parameter to specify the method as Copy, which means no compression.

Example :

7za a -m0=Copy tmp7.7z *.txt

For more info, see -m (Set compression Method) switch.

  • The above command will not compress the txt files and add only the txt files to an existing archive. Before running the above command, an archive file should be created with the non-txt files. Not so easy if there are n different types of files. Sep 18, 2011 at 9:59
  • 6
    If -m0=Copy doesn't work, try -mx=0. Jul 15, 2019 at 5:15

Lets assume you have zip files and you have uncompressed txt files in your folder.

First step is to create a archive compressing txt files using following command.

you can use -m for setting levels of compression , this also depends on compression method you are using

Lets assume here to be default compression only

7z a compressed.7z *.txt -r 

You will get compressed.7z now.

The second step will be to copy the already compressed file to this archive or create a new archive

7z u compressed.7z -u!update.7z -mx0 *.zip 

There is further elaboration of update command here

And in case you have liberty to use graphical interface, the update can be done in a following way

enter image description here

  • 1
    Kind of a hassle but I guess that would work, thanks.
    – user541686
    Sep 24, 2011 at 6:54

Technically, compressed files do not compress further, something about an entropy limit or such, I forget the details, but the most you'd ever get is less than 2% that I've seen.

Most good compressors check the compression and simply store uncompressible files since compressing then would add overhead and increase the size.

Of course, there's the work & time of looking at the file in the first place.

As discussed in other answers, performing multiple passes over your fileset is probably going to be the best solution and is easily scriptable.

Create the 7z archive and add everything BUT the compressed files in one pass, then append the pre-compressed files as non-compressed data. (I'd do it this way since the compressible stuff would then be at the beginning of the archive and the non-compressible all at the end. It would stream off drive faster since it's contiguous)

(used 'compress...' too much!)

  • 1
    In case it helps anyone, here's the gist of "something about an entropy limit or such". Entropy can be thought of as a measure of unpredictability. The idea behind compression is that, if you can predict a pattern of bits, you don't need to store the whole thing... just more compact instructions on how to predict it (a codeword). The theoretical maximum entropy is achieved when it's equally likely that the next codeword could be anything. Squeezing more compression out of compressed data happens when the second pass identifies leftover predictability in the output of the first.
    – ssokolow
    Dec 18, 2015 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.