Overview
The lha command is used to manage and extract LHA files (with the .lzh extension), a compression format that was once very popular in Japan. While it is now a legacy format, it is still necessary when handling old data assets or software archives. In modern Linux environments, the standard lha command is typically used.
Note: Since it is not installed by default on many distributions, you will need to install it manually (e.g., sudo apt install lha or dnf install lha).
Specifications (Arguments and Options)
Syntax
lha [command] [options] [archive_file] [target_files...]
Main Commands (Action Specification)
| Command | Description |
l | List the files in the archive (does not extract). |
x | Extract files while maintaining the directory structure (Recommended). |
e | Extract files (may ignore directory structure depending on the implementation). |
v | Show a detailed list of files. |
t | Test the integrity of the archive (does not extract). |
Main Options (Behavior Modification)
| Option | Description |
f | Force overwrite if a file with the same name exists. |
q | Quiet mode; does not display processing messages. |
w=[DIR] | Specify the destination directory for extraction. |
Basic Usage
It is a safe practice to check the file list before extracting. This allows you to verify the contents and avoid accidentally extracting a large number of files.
# Verify the file type (Confirm it is an LHA archive)
file old_data_v1.lzh
# List the contents
lha l old_data_v1.lzh
Example Result
old_data_v1.lzh: LHa 2.x archive data [lh5, v1, OS-9]
PERMSSN UID GID SIZE RATIO STAMP NAME
---------- ----------- ------- ------ ------------ --------------------
-rw-r--r-- 1000/1000 3412 45.2% Jan 21 10:00 readme.txt
-rw-r--r-- 1000/1000 15820 21.5% Jan 21 10:00 src/main.c
---------- ----------- ------- ------ ------------ --------------------
Total 2 files 19232 31.0%
Practical Commands
Extract While Maintaining Directory Structure
Use the x command to keep the folder hierarchy exactly as it is inside the archive.
# Extract to the current directory while preserving structure
lha x old_data_v1.lzh
Specify the Output Directory
To keep your current directory clean, it is recommended to create a new folder and move into it before extracting.
# Create a directory and extract inside it
mkdir extracted_data
cd extracted_data
lha x ../old_data_v1.lzh
Extract Only Specific Files
You can extract only the files you need instead of the entire archive.
# Extract only readme.txt
lha x old_data_v1.lzh readme.txt
Customization Points
- Forced Overwrite (f): Use the
foption for batch processing when you want to overwrite existing files without confirmation.
# Extract and overwrite without confirmation
lha xf backup.lzh
Important Notes
- Character Encoding Issues: LHA files often save filenames in Shift_JIS (Windows/DOS). Extracting them in a Linux UTF-8 environment can result in garbled filenames. Modern
7zcommands may handle these better. - Security Risks: Since LHA is an old format, some archives may have security vulnerabilities or malicious paths. Always use the
lcommand to inspect the contents and check for absolute paths (like/etc/...) before extracting untrusted files. - Availability: In some distributions like Ubuntu, you may need to enable the
non-freeoruniverserepositories. Iflhais unavailable, look for thejlha-utilspackage or use7z.
Application
Modern Alternative: Extract LHA with 7z
If you cannot install the lha command, the 7z command—standard in many environments—can be used as a substitute.
# Extracting with 7z (requires p7zip-full)
7z x old_data_v1.lzh
Summary
While new LHA files are rarely created today, this command is essential for recovering legacy data. The basic workflow is similar to tar or zip: use l to inspect and x to extract. If you face severe filename corruption, try using the 7z command instead.
