Skip to content

Instantly share code, notes, and snippets.

@Issykul
Last active February 21, 2023 23:59
Show Gist options
  • Save Issykul/ce1b1c0b99de16bb7de1811e01a6e27f to your computer and use it in GitHub Desktop.
Save Issykul/ce1b1c0b99de16bb7de1811e01a6e27f to your computer and use it in GitHub Desktop.
A Cheat Sheet for the 7zz Linux Terminal Utility

7zz Cheat Sheet

Overview

7z [Args] [archive.7z] [files / folders to archive]

A file archiver with highest compression ratio

Args:
a       add
d       delete
e       extract
l       list
t       test
u       update
x       extract with full paths
DO NOT USE the 7-zip format for backup purpose on Linux/Unix.
7-zip does not store the owner/group of the file.

On Linux/Unix, in order to backup directories you must use tar :
  - to backup a directory  : tar cf - directory | 7z a -si directory.tar.7z
  - to restore your backup : 7z x -so directory.tar.7z | tar xf -

If  you  want  to send files and directories (not the owner of file) to others
Unix/MacOS/Windows users, you can use the 7-zip format.

Examples

Example 1:

Quick and Easy - Add all files in dir1 to archive.7z with Default Settings.

7z a archive.7z dir1

Example 2:

Create a 7zip archive on Compression Level Ultra (-mx9) and split it into 4GB sized volumes (-v4g)

7zz a -mx9 -v4g archive.7z dir1

Example 3:

Add all files in dir1 to archive.7z with Max Compression

7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on archive.7z dir1

    -t7z        7z archive
    -m0=lzma    lzma method
    -mx=9       level of compression = 9 (ultra)
    -mfb=64     number of fast bytes for lzma = 64
    -md=32m     dictionary size = 32 Mb
    -ms=on      solid archive = on

Example 4:

Add (store) all files in dir1 to archive.7z with No Compression

7z a -m0=copy archive.7z dir1

7z exit codes:

0       normal (no errors or warnings)
1       warning (non-fatal errors)
2       fatal error
7       bad cli arguments
8       not enough memory for operation
255     process was interrupted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment