Linux Command Manual
\n\nLinux lha Command
\n\nThe Linux lha command is used to compress or decompress files.
\n\nlha is a command-line tool used in Linux systems to handle .lzh and .lha compressed files. It was originally developed to process the LHA compression format popular in Japan and is still used in certain specific scenarios.
Main Features
\n- \n
- Supports compressing and decompressing
.lzhand.lhaformat files \n - Compatible with old DOS/Windows compressed files \n
- Lightweight, suitable for resource-limited environments \n
- Preserves original file attributes (such as timestamps) \n
\n\n
Installing the lha Tool
\n\nIn most Linux distributions, lha is not a pre-installed tool and needs to be installed manually:
\n\nUbuntu/Debian Systems
\n\nsudo apt-get update\nsudo apt-get install lha\n\nCentOS/RHEL Systems
\n\nsudo yum install lha\n\nVerify Installation
\n\nlha --version\n\n\n\n
Basic Command Syntax
\n\nThe basic syntax format of the lha command is:
\n\nlha command archive [files/directories...]\n\nCommon Command Parameters
\n\n| Command | \nDescription | \n
|---|---|
| a | \nAdd files to an archive | \n
| e | \nExtract files (without preserving paths) | \n
| x | \nExtract files (preserving full paths) | \n
| l | \nList archive contents | \n
| t | \nTest archive integrity | \n
| d | \nDelete files from an archive | \n
Common Option Parameters
\n\n| Option | \nDescription | \n
|---|---|
| -v | \nDisplay detailed operation information | \n
| -q | \nQuiet mode (no output displayed) | \n
| -f | \nForce operation | \n
| -x | \nAllow extended attributes | \n
| -p | \nPreserve file permissions | \n
\n\n
Usage Examples
\n\n1. Creating an Archive
\n\nCompress the project directory into project.lzh:
lha a project.lzh project/\n\nAdd multiple files and directories:
\n\nlha a archive.lzh file1.txt file2.txt dir1/\n\n2. Listing Archive Contents
\n\nView the file list in archive.lzh:
lha l archive.lzh\n\nExample output:
\n\n PERMISSION UID GID SIZE RATIO STAMP NAME\n ---------- ----------- ------- ------ ------------ --------------------\n -rw-r--r-- 1000/1000 1024 65.3% May 15 10:00 file1.txt\n -rw-r--r-- 1000/1000 2048 70.1% May 15 10:05 file2.txt\n drwxr-xr-x 1000/1000 0 0.0% May 15 09:55 dir1/\n\n3. Extracting Files
\n\nExtract to the current directory (without preserving paths):
\n\nlha e archive.lzh\n\nExtract while preserving the full directory structure:
\n\nlha x archive.lzh\n\nExtract a specific file:
\n\nlha e archive.lzh file1.txt\n\n4. Testing Archive Integrity
\n\nlha t archive.lzh\n\n5. Deleting Files from an Archive
\n\nDelete file1.txt from archive.lzh:
lha d archive.lzh file1.txt\n\n\n\n
Advanced Usage
\n\n1. Split Compression
\n\nCreate a split archive (1MB per volume):
\n\nlha -v-s1024k a archive.lzh large_dir/\n\n2. Setting Compression Level
\n\nSpecify compression level (0-5, default 2):
\n\nlha -2 a archive.lzh files/ # Higher compression ratio\nlha -0 a archive.lzh files/ # Store only, no compression\n\n3. Excluding Specific Files
\n\nUse -x to exclude files:
lha a -x*.tmp archive.lzh dir/\n\n\n\n
Frequently Asked Questions
\n\nQ1: What is the difference between lha and zip/gzip?
\n- \n
- lha is a tool specifically for handling
.lzh/.lhaformats. \n - Its compression ratio is usually not as good as gzip/bzip2. \n
- Its main advantage is compatibility with old Japanese system files. \n
Q2: How to extract a password-protected .lzh file?
\nlha itself does not support password protection. You need to use other tools like unar:
unar -p password protected.lzh\n\nQ3: Why isn't my lha command working?
\nPossible reasons:
\n- \n
- The lha tool is not installed (see the installation section). \n
- File permission issues (try using
sudo). \n - The archive file is corrupted (use
lha tto test). \n
\n\n
Best Practice Recommendations
\n\n- \n
- Compatibility Considerations: Only use lha when you need to handle old system files. For new projects, it is recommended to use more universal formats like zip or tar.gz. \n
- Use in Scripts: Add the
-qoption to avoid output interference:\n
\nlha -q a backup.lzh /path/to/files\n - Combine with find: Compress specific types of files:\n
\nfind . -name"*.txt"-exec lha a textfiles.lzh {} +\n - Backup Scenarios: Preserve file attributes:\n
\nlha -p a backup.lzh important_dir/\n
\n\n
Alternative Tools
\n\nAlthough lha has its specific uses, modern Linux systems more commonly use these tools:
\n\n| Tool | \nFormat | \nCharacteristics | \n
|---|---|---|
| tar | \n.tar | \nArchiving only, no compression | \n
| gzip | \n.gz | \nHigh compression ratio | \n
| bzip2 | \n.bz2 | \nHigher compression ratio, slower speed | \n
| xz | \n.xz | \nExtremely high compression ratio | \n
| zip | \n.zip | \nCross-platform compatibility | \n
| 7z | \n.7z | \nSupports multiple compression algorithms | \n
YouTip