The Archive Extractor is a Bash script designed to automate the extraction of various archive formats. It provides flexible options for processing archives, including batch extraction, post-processing actions, and detailed logging capabilities.
The script was created using language models: Claude, ChatGPT, Gemini.
Read the story behind.
- Supports multiple archive formats:
.tar.gz,.tar.7z,.tar.bz2,.tar.xz,.7z,.zip - Configurable through command-line options or environment variables
- Post-processing options: moving, removing, or marking processed files
- Detailed logging with different verbosity levels
- Pretend mode for testing configurations
- Processing limit of 100 files per run
- Fallback options for different extraction tools
The script requires one or more of the following commands based on the archive formats you want to process:
tar: For handling tar-based archives (.tar.gz,.tar.bz2,.tar.xz)7z: For handling.7zfiles and as a fallback for.zipfilesunzip: Primary handler for.zipfiles
./extractor.sh [options]| Option | Long Option | Description | Default |
|---|---|---|---|
-c |
--config |
Configuration file path | .env |
-s |
--search |
Directory to scan for archives | . |
-o |
--output |
Directory to extract archives to | Current directory |
-a |
--archive |
Directory to move processed archives to | None |
-m |
--mark |
Mark file extension | .mark |
-r |
--remove |
Remove archives after processing | Disabled |
-v |
--verbose |
Enable detailed logging | Disabled |
-q |
--quiet |
Suppress all non-error output | Disabled |
-p |
--pretend |
Show operations without executing them | Disabled |
-h |
--help |
Show help message | N/A |
The script can be configured using environment variables, which can be set directly or through a configuration file:
CONFIG: Path to configuration fileSEARCH: Directory to scan for archivesOUTPUT: Extraction output directoryARCHIVE: Directory for processed archivesMARK: Mark file extensionREMOVE: Remove archives after processingVERBOSE: Enable verbose loggingQUIET: Suppress non-error outputPRETEND: Enable pretend mode
The script supports configuration through an environment file (default: .env). Example configuration:
SEARCH="/path/to/archives"
OUTPUT="/path/to/output"
ARCHIVE="/path/to/processed"
MARK=".processed"
REMOVE="0"
VERBOSE="1"The script provides three mutually exclusive post-processing options:
- Archive: Move processed files to an archive directory
- Remove: Delete processed files
- Mark: Create a mark file to indicate processing completion
0: No archives processed, or all operations successful1-100: Number of successfully processed archives255: Error occurred during processing
- Basic usage with default options:
./extractor.sh- Extract to specific directory with verbose logging:
./extractor.sh --output /path/to/output --verbose- Process archives and move them to an archive directory:
./extractor.sh --search /path/to/archives --archive /path/to/processed- Test configuration without actual processing:
./extractor.sh --pretend --verboseThe script provides four logging levels:
- Error: Always displayed (stderr)
- Warning: Displayed unless quiet mode is enabled
- Info: Displayed unless quiet mode is enabled
- Verbose: Only displayed when verbose mode is enabled
- Maximum processing limit of 100 files per run
- Only processes files in the immediate search directory (depth=1)
- Requires appropriate extraction tools for different archive formats
- Validates directories before processing
- Checks for required commands before extraction
- Reports detailed error messages
- Maintains count of errors encountered
- Always test new configurations with
--pretendmode first - Use verbose mode (
-v) for detailed operation logging - Consider using mark files instead of removing archives for safety
- Check exit codes for automated processing
- Ensure required extraction tools are installed for your archive types