7-Zip (7z)

I have a 7z archive named test.7z. This archive is uncompressed. I want to compress test.7z with 7z compression. How could I compress it using the same filename? The following command is the only way I was able to compress it using the same filename: 7z a output.7z test.7z && mv output.7z test.7z.

There has to be a better syntax to accomplish this. Any ideas?
 
If not specified 7z is the default compression. If you want to specify then it would be 7z a -t7z file.7z source. If you want to set ultra compression too then it would look like 7z a -t7z -mx=9 file.7z source. I've tried using the update switch ( 7z u -t7z -mx=9 file.7z) on a compressed file but it always seems to double the file size, so I just use it to add more files to an archive.
 
You guys are not understanding what I'm asking.

I have an UNCOMPRESSED archive named test.7z. Just because this file (test.7z) has a .7z extension does not mean it's compressed. It's just an ARCHIVE.

Hint: Using -mx=0 creates an UNCOMPRESSED archive. OK, now that we got that squared away...

Question: What do I want to do with this UNCOMPRESSED archive named test.7z?

Answer: I want to compress it with the default ratio (AKA: -mx=5)....but the key is I want the name of the file to stay the same (which would be test.7z).

Right now I have this command to accomplish this: 7z a output.7z test.7z && mv output.7z test.7z.

But I know there has to be a better syntax to accomplish this. Any ideas?
 
Niatross said:
7z a [b]-t7z[/b] file.7z source

Hint: Never use " -t7z[/b" in your command (above). Just use the extension".7z" and 7-zip will figure out what type of compression you want to use.

Hint: It defaults to 7z unless otherwise indicated, per the man page.
 
I don't think there is any syntax to 7z that will do what you want, and I wouldn't want to be shooting myself in the foot by having a command overwrite the input file with the output it's generating. Are you wanting the final result to be compressed archive that can be extracted by simply typing 7z x test.7z? That's no going to happen unless you extract the current test.7z into some temporary spot and then rebuild the archive, giving the compression level that you really want. If you don't do that, and use the "archive and rename" method that you had in your initial post, it's going to be a two-step process to extract the original files: the first "extraction" will basically "uncompress" the original archive, and the second step will be needed to pull everything out of that original archive; if I wanted to do that, I'd just gzip/ xz/ lzma/... the original test.7z and leave the new file with whatever .gz/.xz/.lzma/... suffix got put on it so that I'd know exactly what it was.
 
ljboiler said:
I don't think there is any syntax to 7z that will do what you want, and I wouldn't want to be shooting myself in the foot by having a command overwrite the input file with the output it's generating. Are you wanting the final result to be compressed archive that can be extracted by simply typing 7z x test.7z? That's no going to happen unless you extract the current test.7z into some temporary spot and then rebuild the archive, giving the compression level that you really want. If you don't do that, and use the "archive and rename" method that you had in your initial post, it's going to be a two-step process to extract the original files: the first "extraction" will basically "uncompress" the original archive, and the second step will be needed to pull everything out of that original archive; if I wanted to do that, I'd just gzip/xz/lzma/... the original test.7z and leave the new file with whatever .gz/.xz/.lzma/... suffix got put on it so that I'd know exactly what it was.

Thanks for answering my post. Appreciate it. Didn't know if my syntax was the only way to go about it.
 
Back
Top