Field Notes
Engineering

7zr on the Command Line

Compressing and extracting archives with the 7-Zip CLI.

1 min read

7zr is a command-line version of the 7-Zip compression tool. It supports a variety of compression formats, including 7z, ZIP, GZIP, BZIP2, and more. Here are some basic usage examples:

Compressing files or folders ​

bash
7zr a [archive_name].7z [file_or_folder_to_compress]
  • The a argument means "add to archive" (the compression operation).
  • [archive_name].7z is the archive file name you specify; .7z is the default 7-Zip compression format extension.
  • [file_or_folder_to_compress] is the path to the actual file or folder you want to compress.

For example, to compress the test folder in the current directory:

bash
7zr a test.7z test

Extracting files ​

bash
7zr x [archive_name].7z -o[output_directory]
  • The x argument means "extract" (the decompression operation).
  • [archive_name].7z is the archive you want to extract.
  • -o[output_directory] specifies the target folder to extract into.

For example, to extract test.7z into an extracted folder in the current directory:

bash
7zr x test.7z -oextracted

Listing the contents of an archive ​

bash
7zr l [archive_name].7z
  • The l argument lists the contents of the archive (the file listing).

For example, to list the contents of test.7z:

bash
7zr l test.7z

These commands will help you compress and decompress files with 7zr from the command line. Before using it, remember to make sure you have installed the 7-Zip tool and the corresponding command-line version.