7z
Archives
Usage
7z <a|x|l> <archive.7z> [files]Takes a verb first — `a` to add, `x` to extract with paths, `e` to flatten them, `l` to list — reads far more than .7z including zip, tar and rar, and packs tighter than most; the output directory goes right after `-o` with no space, and `-mhe=on` alongside `-p` is what also hides the file names.
Common flags
| Flag | Meaning |
|---|---|
| a | Add or create. |
| x | Extract keeping the stored directory structure. |
| e | Extract everything into one directory, flattening paths. |
| l | List the contents. |
| -o<dir> | Output directory, written with no space after -o. |
| -p<password> | Password. Add -mhe=on to encrypt the file names too. |
| -mx=9 | Maximum compression. |
| -t7z / -tzip | Choose the output format. |
Examples
7z a -mx=9 backup.7z ./dataA tightly compressed archive.
7z x archive.7z -o/tmp/outExtract with the folder structure intact.
7z a -p -mhe=on secret.7z ./docsEncrypt the contents and the file names, with a prompted password.
Bundling and compressing are separate jobs: tar bundles, gzip shrinks, and .tar.gz is both.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does 7z do?
Takes a verb first — `a` to add, `x` to extract with paths, `e` to flatten them, `l` to list — reads far more than .7z including zip, tar and rar, and packs tighter than most; the output directory goes right after `-o` with no space, and `-mhe=on` alongside `-p` is what also hides the file names.
Q. How do I type it?
7z <a|x|l> <archive.7z> [files] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
8 are listed here; the full set is in man 7z. This command sits under Archives.
Related commands
man page: man 7z