Home
Website
7-Zip Tar Command Lines
Updated Mar 7, 2025
Dot Net Perls
7-Zip, Tar. It is possible to use the "tar" command to create and expand 7-Zip (7z) files. On platforms like macOS that have tar, no separate 7-Zip program is needed.
7-Zip Command Line
With the "a" flag, we tell tar to compress an archive based on the specified file name. So if we use a ".7z" extension, 7-Zip is used.
Compress. To begin we need to compress an archive. Suppose we are in a folder with a directory named "work" that we want to compress with 7-Zip.
Part 1 We specify "a" for auto mode, and then "c" to indicate we want to compress, and the "f" means we are specifying the target file.
Part 2 To specify more powerful compression with 7-Zip, use the options flag and specify the 7-Zip compression level. The value 9 is the maximum.
' Part 1: for default compression with tar and 7-zip: tar -acf archive.tar.7z work ' Part 2: for optimal compression: tar --options 7zip:compression-level=9 -acf archive.tar.7z work
Extract. On macOS, Windows and Linux it is usually possible to expand the archive by clicking on it. But we can use tar to do this directly, which is sometimes desired.
Tip The "x" flag means expand, and the "f" means we are specifying the file name to expand. Tar automatically detects the format when expanding.
Further We create a temp folder, and then expand into it with the "C" flag (this flag is not always needed).
' To decompress 7z file with tar: mkdir temp tar -xf archive.tar.7z -C temp
Notes, commands. When using tar, it is important to specify "c" or "x" to compress or expand. And "a" means tar can detect the compression format from the file name.
Finally The "f" flag is used on most every command line, as it means we are specifying an archive file (to read or write).
' Some tar flags: a - auto compress c - create new x - expand existing archive f - file to use (can read from archive or write to file)
The 7-Zip format is both efficient and widely-used. It can compress better than many other formats, and even programs like tar can handle it.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Mar 7, 2025 (image).
Home
Changes
© 2007-2025 Sam Allen