With an increasing number of archive/compression file formats, is there a single free/open-source command line tool to rule them all? Perhaps something with a consistent / unified set of flags? (note my friendly implicit reference to tar)
I once run into a set of aliases meant to largely simplify the task of compressing/de-compressing files with bindings to tar and other utils, but I can’t find this anymore.
Update:
How can I configure something like atool to not use unzip to extract zip files (which apparently can’t handle files larger than 4GB) and to use gunzip instead?
$ aunpack large_file.zip error: Zip file too big (greater than 4294959102 bytes) Archive: large_file.zip warning [large_file.zip]: 1491344848 extra bytes at beginning or within zipfile (attempting to process anyway) error [large_file.zip]: start of central directory not found; zipfile corrupt. (please check that you have transferred or created the zipfile in the appropriate BINARY mode and that you have compiled UnZip properly) aunpack: unzip ...: non-zero return-code
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I use atool. It does the job. It works with many, though not all formats:
tar, gzip, bzip2, bzip, lzip, lzop, lzma, zip, rar, lha, arj, arc, p7zip etc.
These compression tools are still needed, though as atool is simply a front end for them.
I particularly like the als command it provides which lists the contents of any supported archive format.
The main atool command uses its own flags for extracting archives (passing the appropriate flags to the specific underlying extraction tools).
Oh, and it’s in some distributions’ repositories (Fedora in my case, though as I recall, back when I used Ubuntu it wasn’t in their repos then. and I installed from a tarball.).
Update on Repositories: atool is in the following distributions’ repositories (current releases checked only):
- Fedora
- Debian (thanks @terdon, and, presumably, it’s derivatives
like Ubuntu) - Ubuntu (q.e.d., and, presumably, derivatives like
Mint) - Open Suse
- CentOS (and, presumably, RHEL)
- Arch Linux
I’m sure there are others… plausibly, most modern distributions.
Answer for Updated Question “How can I configure something like atool to not use unzip to extract zip files … and to use gunzip instead”:
Edit the atool config file ~/.atoolrc and add the line:
path_unzip /usr/bin/gunzip
with the correct path to your gunzip program.
See the man page for the complete list of possible variables you can put in this config file, of which there are a lot. If the command line options necessary for gunzip are different than unzip, you may have to modify the atool source (perl) itself.
Method 2
Here’s a little shell function that takes care of several archive types.
extract () {
if [ ! -f "$1" ] ; then
echo "'$1' does not exist."
return 1
fi
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.xz) tar xvJf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) rar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.xz) xz -d "$1" ;;
*.7z) 7z x "$1" ;;
*.a) ar x "$1" ;;
*) echo "Unable to extract '$1'." ;;
esac
}
I found the original
version of this function
somewhere online and modified it a bit to extract ar archives and xz
compressed tar archives.
Method 3
The AVFS filesystem presents a view of the filesystem where every archive file (e.g. /path/to/foo.zip) is accessible as a directory (~/.avfs/path/to/foo/zip# for this example). AVFS provides read-only access to most common archive file formats.
mountavfs cp -Rp ~/.avfs$PWD/large_file.zip# extraction_directory
Avfs uses external helpers which can be easily configured by editing files in /usr (unfortunately there’s no way as of avfs 1.0 to use files in /usr/local or in your home directory, you need to edit files in /usr or recompile). /usr/share/avfs/extfs/ext-uzip is the script to deal with .zip files, change it if you don’t want to use /usr/bin/unzip. You may be able to get away with using 7z instead: try editing /usr/share/avfs/extfs/extfs.ini and change the line ext-uzip to u7z .zip.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0