A smart, safe decompression tool that handles any compressed file without the hassle!
Hmm... Was it
tar -xzffor tar files? Or is that for .gzip? Am I doing this right for this .zip file? What about .xz files? And wait, is this actually a real archive or just a text file someone renamed?
Who cares! Just run decompress filename.whatever and your file will be safely extracted with intelligent defaults and security checks. No more memorizing arcane command-line switches!
- Auto-detection: Supports 12+ archive formats with automatic tool detection
- File verification: Uses the
filecommand to verify archives are actually what they claim to be - Dependency checking: Automatically checks if required tools are installed before attempting extraction
###️ Safety First
- Security scanning: Detects potentially malicious archives with path traversal attacks (
../../../etc/passwd) - Content preview: Shows what will be extracted before doing it
- Clutter prevention: Warns when multiple items would be created in current directory
- Interactive choices: Lets you decide how to handle potentially messy extractions
- Destination control: Extract to any directory with
decompress archive.tar.gz ./target_folder - Auto-creation: Creates destination directories if they don't exist
- Smart cleanup: Optional removal of source files after successful extraction
- Clear feedback: Detailed progress and error messages
| Format | Extensions | Tool Required |
|---|---|---|
| Tar | .tar |
tar |
| Gzip Tar | .tar.gz, .tgz |
tar |
| Bzip2 Tar | .tar.bz2, .tbz2 |
tar |
| XZ Tar | .tar.xz |
tar |
| Gzip | .gz |
gunzip |
| Bzip2 | .bz2 |
bunzip2 |
| XZ | .xz |
xz |
| Zip | .zip |
unzip |
| RAR | .rar |
unrar or rar |
| 7-Zip | .7z |
7z |
| Compress | .Z |
uncompress |
# Extract to current directory
decompress archive.tar.gz
# Extract to specific directory
decompress archive.zip ./extracted_files
# Extract to new directory (will be created)
decompress data.7z /tmp/my_dataSimple extraction:
$ decompress photos.zip
File type verified: Zip archive data, at least v2.0 to extract
Previewing archive contents...
Archive contains 1 top-level items:
photos/
Extracting 'photos.zip'...
Extraction completed successfully
Do you want to remove the original file (photos.zip) [Y/n]? y
Original file 'photos.zip' removedMulti-item archive with safety prompt:
$ decompress messy-archive.tar.gz
File type verified: gzip compressed data, tar archive
Previewing archive contents...
Archive contains 8 top-level items:
README.md
src/
docs/
config.ini
...
This will create multiple items in the current directory.
Options:
1) Continue extraction to current directory
2) Extract to a new subdirectory
3) Cancel extraction
Choose [1/2/3]: 2
Enter subdirectory name (will be created): my_project
Created directory 'my_project'
Extracting 'messy-archive.tar.gz'...
Extraction completed successfully
Contents extracted to: my_projectSecurity warning example:
$ decompress suspicious.tar
File type verified: tar archive
Previewing archive contents...
WARNING: Archive contains paths with '..' which could extract outside the target directory
Suspicious paths found:
../../../etc/passwd
../../config/secrets
Do you want to continue anyway? [y/N]: n
Extraction aborted# Make executable and install system-wide
chmod +x decompress
sudo cp decompress /usr/local/bin/
# Now you can run it from anywhere!
decompress ~/Downloads/archive.tar.gzThe script will automatically check for required tools. Install missing ones:
Ubuntu/Debian:
sudo apt install tar gzip bzip2 xz-utils unzip unrar p7zip-fullCentOS/RHEL/Fedora:
sudo dnf install tar gzip bzip2 xz unzip unrar p7zipmacOS (with Homebrew):
brew install gnu-tar gzip bzip2 xz unzip unrar p7zipThe script uses the file command to verify that archives match their extensions:
- Prevents extraction of files with misleading extensions
- Catches corrupted or incomplete downloads
- Adds security against disguised malicious files
- Auto-creation: Destination directories are created if they don't exist
- Validation: Ensures destination is writable and not a file
- Path safety: Validates destination paths for security
- Path traversal detection: Warns about
../paths that could extract outside target - Multi-item prevention: Prevents accidentally cluttering current directory
- User choice: Always gives you control over potentially risky operations
"Command not found" errors:
ERROR: 'unrar' is not installed or not in PATH
Please install 'unrar' to use this scriptInstall the missing tool using your package manager.
"File type mismatch" errors:
ERROR: File type mismatch for 'fake.tar.gz'
Expected: gzip compressed.*tar archive
Detected: ASCII textThe file extension doesn't match the actual file type. Check if the file was corrupted during download or incorrectly named.
Permission errors:
ERROR: Destination directory './restricted' is not writableEnsure you have write permissions to the destination directory.
This script is provided as-is for educational and practical use. Feel free to modify and distribute!
Found a bug or want to add support for another archive format? Pull requests welcome!