Thursday, September 28, 2023
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 1466  / 2 Years ago, sat, june 12, 2021, 9:26:01

Usually I use tar for *.tar archives, zip/unzip for *.zip, 7z for *.7z , etc... Is there an über utility that combine all algorithms?



Here is pseudo usage of this utility:



Extracting:



$ unpack *.tar -d /home/c0rp/this_is_tar
$ unpack *.rar -d /home/c0rp/this_is_rar
$ unpack *.tar.gz -d /home/c0rp/this_is_targz
$ unpack *.zip -d /home/c0rp/this_is_zip
$ unpack *.7z -d /home/c0rp/this_is_7z


Compressing:



$ pack some_name.tar /home/c0rp/for_tar1 /home/c0rp/for_tar2
$ pack some_name.rar /home/c0rp/for_rar1 /home/c0rp/for_rar2
$ pack some_name.tar.gz /home/c0rp/for_targz1 /home/c0rp/for_targz2
$ pack some_name.zip /home/c0rp/for_zip1 /home/c0rp/for_zip2
$ pack some_name.7z /home/c0rp/for_zip1 /home/c0rp/for_7z

More From » command-line

 Answers
2

I just realized that 7-Zip (command 7z) can do it. 7-Zip is able to extract and compress many types of archives. Here is a quote from man 7z:



DESCRIPTION
7-Zip is a file archiver with the highest compression ratio. The pro-
gram supports 7z (that implements LZMA compression algorithm), LZMA2,
XZ, ZIP, Zip64, CAB, RAR (if the non-free p7zip-rar package is
installed), ARJ, GZIP, BZIP2, TAR, CPIO, RPM, ISO, most filesystem
images and DEB formats...


7-Zip can extract/compress archives and is detecting the compressing algorithm itself.



This should work as you are expecting:



Compressing



$ 7z a file.tar.gz file
$ 7z a file.zip file
$ 7z a file.7z file
$ 7z a file.gzip file


Extracting



$ 7z x file.tar.gz
$ 7z x file.zip
$ 7z x file.7z
$ 7z x file.gzip





Also here is a little test. Here I create five archives and give them different filename extensions.



$ cd /tmp
$ touch testfile
$ for alg in {zip,gzip,7z,tar.gz,rar};do 7z a testfile."$alg" testfile;done
$ ls testfile*
testfile.7z
testfile.gzip
testfile.rar
testfile.tar.gz
testfile.zip


Now to detect the compressing algorithm, I will use the binwalk utility.



$ for arch in testfile.*;do binwalk "$arch" | sed -n '4p' | awk {'print $3'};done
7-zip
gzip
7-zip
gzip
Zip

[#22309] Saturday, June 12, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
herriail

Total Points: 11
Total Questions: 122
Total Answers: 118

Location: Peru
Member since Tue, Mar 16, 2021
3 Years ago
;