Scroll to navigation

lha(1) General Commands Manual lha(1)

NAME

lha - compression tool for .lzh archive files.

SYNOPSIS

lha [-]{lvtxep[q{num}][finv]}[w=<dir>] archive_file [file ...]

DESCRIPTION

lha is a tool for extracting .lzh archive files. It also supports variants of the .lzh archive, such as .lzs and .pma.

This version of the lha tool is part of Lhasa, a free implementation of the .lzh format.

COMMAND SYNTAX

The lha tool has an unusual command syntax, compared to most other Unix commands. The first parameter to the program specifies the command to perform and all additional options. The second parameter specifies the path to the archive file to operate on. Following this is a list of wildcard patterns to match against the filenames of the archived files.

The first character of the command parameter specifies the command to perform, which is one of the following:

List contents of the specified archive.
Verbosely list contents of the specified archive.
Test the integrity of the specified archive: decompress its contents and check the CRC.
Extract archive. Files are extracted to the current working directory unless the 'w' option is specified.
Extract archive, sending decompressed files to stdout rather than writing them to the filesystem as actual files. This is useful when used as part of a shell pipeline.

OPTIONS

The remainder of the command parameter is used to specify additional options:

Quiet mode. Higher numbers suppress more output. Level 0 is normal operation. If no number is specified, full suppression (level 2) is used. The quiet option also turns on the force overwrite option ('f').
Force overwrite of existing files: do not prompt.
Ignore paths of archived files: extract all archived files to the same directory, ignoring subdirectories.
Do not perform any actual operations: instead, perform a dry run of the requested operation and describe what would have been done on standard output.
Verbose mode: causes extra information to be written to standard output.
Specify destination directory for extracting files. This must be the last option of the first parameter.

LIST OUTPUT FORMAT

Lhasa inherits its list output format from the original Unix port of lha, and retains the same format for compatibility, since some tools parse the output. Four different output formats are supported, depending on the command line arguments:

Shows: Unix permissions / OS type, UID/GID, uncompressed size, compression ratio, modification time, filename.
Two line output. First line shows the filename, second line shows: Unix permissions / OS type, UID/GID, uncompressed size, compression ratio, modification time, filename, header level.
Shows: Unix permissions / OS type, UID/GID, compressed size, uncompressed size, compression ratio, compression format, checksum, modification time, filename.
Two line output. First line shows the filename, second line shows: Unix permissions / OS type, UID/GID, compressed size, uncompressed size, compression ratio, compression format, checksum, long form modification time, header level.

The following are detailed descriptions of each of these fields:

For files compressed on a Unix system, this lists the permissions in the same format that ls(1) uses when it is invoked with the -l option. If the file was not created on a Unix system, the OS type is instead displayed in square brackets. Examples are "[MS-DOS]" and "[MacOS]"; the OS name never contains a space. If the file was created on Microware OS-9, the permissions for that system will also be shown.
For files compressed on a Unix system, this lists the user and group IDs of the file, similar to the output seen from ls(1) when it is invoked with the -ln option. If the file was not created on a Unix system, "*****/*****" is shown; see LIST FORMAT DIFFERENCES below.
Size of the file in bytes as it is stored inside the archive (not including the header, which contains metadata about the file). If an uncompressed format like -lh0- is used, this will be equal to SIZE.
Size of the file in bytes before it was compressed.
Compressed size as a percentage of uncompressed size. This measures the effectiveness of the compression format; the smaller the percentage, the better. The value is (pessimistically) rounded up to the next 0.1%. If an uncompressed format like -lh0- is used, this will be equal to 100%. For directories, "******" is shown. Note that the value here is backwards relative to unzip(1), which instead shows the percentage of the original file size reduced.
The compression format used to store this file. See the COMPRESSION FORMATS section below.
CRC16 checksum of the file's contents in hexadecimal format. Warning: while this is useful for casually checking file integrity, it is only a 16-bit checksum and should not be considered reliable for protecting files larger than a few kilobytes.
Date and time that the file was last modified before it was stored in the archive. If the file doesn't have a timestamp stored, nothing is shown. The output can be in one of two forms: if the date is within the past six months, the month, day and time are shown; an example is "Aug 24 12:38". For older files, the month, day and year are shown; an example is "Aug 24 2020".
This is only used when listing in the -vv format. The full date and timestamp are listed in numeric form, close to ISO 8601 format (though not quite conformant with that standard). An example is "2020-08-24 12:38:25".
Lha header format used to store this file. Supported formats are 0-3.

LIST FORMAT DIFFERENCES

The list mode output from the original Unix lha tool was not designed to be machine-readable. Since some tools do try to parse the list output, Lhasa's list output has been deliberately tweaked slightly to make the output more consistent and easier to parse.

Here are the main differences:

  • If a file was not created on a Unix system, a spacer word is shown in the UID/GID column. The original lha just showed whitespace.
  • The OS type for archives generated by MacLHA is listed as "MacOS" (no space). The original lha showed "Mac OS".

Note that in general, the approach of parsing text output is inherently fragile and prone to bugs. It's recommended that you instead use the proper API (liblhasa).

COMPRESSION FORMATS

The following gives some basic description of the various different supported compression formats (as listed when using the list command documented above). All formats are variants on the LZSS compression algorithm.

Uncompressed (stored) data, as used by the original LArc tool. This is not related to the LZ4 compression algorithm of the same name.
Compression formats introduced with the original LArc tool. -lzs- uses a 2KiB sliding window while -lz5- uses a 4KiB window.
Directory entry. No data is stored, only headers.
Uncompressed (stored) data, as used in LHarc and LHa.
Compression algorithm introduced with LHarc. This uses a 4KiB sliding window with dynamic Huffman encoding.
New algorithm introduced with LHa (aka LHarc v2.0). The original versions (-lh4- and -lh5-) used 8KiB and 16KiB sliding window sizes, respectively. Later versions introduced new variants with larger window sizes: -lh6- (64KiB) and -lh7- (128KiB).
Variant on the -lh4- format listed above introduced by UNLHA32.dll that extends the window size to 1MiB.
Variant on the -lh4- format listed above that was introduced by the LHark tool (a fork of LHa). This is actually named -lh7- within the archive files, but Lhasa renames it internally to avoid clashing with the other algorithm of the same name. Uses a 128KiB sliding window, with some minor improvement to the algorithm.
Uncompressed (stored) data, as used by the PMarc tool.
Algorithm used by version 1 of the PMarc tool.
Algorithm used by version 2 of the PMarc tool.

UNSUPPORTED FORMATS

The following formats are not currently supported by Lhasa (but possibly will be in the future):

These formats can be decompressed by LHa v2.0 but the tool could not actually generate archives with these formats; they appear to have only been supported in beta versions before the v2.0 release. As a result, few if any examples exist in the wild.
Extensions of the -lh4- format to even larger window sizes.
Generated by ThunderSoft's PAKLEO utility (.pll).
Used in SourceWare Archival Group's .swg (SWAG packet) format.
Generated by LDarc and LDIFF (.lzd).
Generated by the Micrognosis Compression Archiver utility.
Format generated by the PopCom! compression utility for CP/M.

If you encounter examples of these in the wild, please get in touch.

EXAMPLES

Here are some examples for how to invoke the program:

List the contents of the file foobar.lzs (producing verbose output).
Extract the contents of a self-extracting archive file named foobar.exe to the current directory, overwriting existing files with the same names if they exist.
Extract the contents of foobar.lzh to /tmp, overwriting any existing files found there, and suppressing normal output (similar to how other Unix tools such as cp(1) or tar(1) act silently by default).

WWW

https://lhasa.soulsphere.org/

BUG REPORTS

Bugs can be reported to the GitHub issue tracker: https://github.com/fragglet/lhasa

SEE ALSO

unzip(1), tar(1), gzip(1), bzip2(1), xz(1), lzip(1)

HISTORY

The .lzh format originated with Kazuhiko Miki's MS-DOS archive tool, LArc, using the LZSS algorithm developed by Haruhiko Okumura, and the .lzs filename extension. The container format was reused for LHarc, by Haruyasu Yoshizaki (Yoshi), which used a new algorithm named LZHUF and the .lzh extension. In later versions, LHarc was renamed to LHA and extended with more effective compression algorithms.

Versions of the LHA tool were later ported to various different operating systems, including the Amiga, Atari, MacOS, OS/2 and Unix. A tool for MSX-DOS named PMarc reused the container format with a new compression algorithm (.pma extension).

The Unix version of the tool was developed by Masaru Oki, Nobutaka Watazaki and Tsugio Okamoto, but was released under a software license that does not conform to the Free Software or Open Source Definitions. Lhasa was developed as a drop-in replacement that is Free Software and Open Source.

The name "LHA" and the .lzh filename extension are a reference to the compression algorithm: a combination of Lempel–Ziv–Storer–Szymanski dictionary coding and Huffman encoding. Similar schemes are used in other compression algorithms such as Deflate (used in gzip/zlib, PNG image files, and the .zip format).

BUGS

The current version does not allow the creation of new archive files.

Some obscure compression algorithms are not currently supported (see the UNSUPPORTED FORMATS section above).

The tool does not currently do text format conversion for non-ASCII filenames when listing the contents of archives. Non-ASCII characters are replaced by a question mark.

AUTHOR

Lhasa was written and is maintained by Simon Howard.

COPYRIGHT

Copyright © 2011-2025 Simon Howard.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.