Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Re-compress any archive to tar.xz with maximum compression level ###
- ### ACCEPTS THESE ARCHIVES ###
- # tar, gzip, bzip2, xz, zip, 7zip, rar
- ### USAGE ###
- # arch2xz filename1.tar.gz filename2.tar.bz2 filename3.zip ...etc...
- ### NOTE ###
- # you can feed the function with INPUT files ONLY
- # you CAN NOT specify the output files
- # output files have the same filename as their input counterpart, only the extension is different
- function arch2xz () {
- if [[ -z $1 ]]; then
- echo "arch2xz <file> <file>..."
- echo ""
- echo "Accepted compression formats: tar, gzip, bzip2, xz, zip, 7zip, rar"
- echo ""
- echo "NOTE: p7zip is required to handle 7zip and rar files"
- return 1;
- fi
- archives=("$@")
- for i in "${archives[@]}"
- do
- if [ -f $i ] ; then
- case $i in
- *.tar.bz2) bzip2 -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
- *.tar.gz) gzip -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
- *.tar.xz) xz -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.new.tar.xz ;;
- *.bz2) bzip2 -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
- *.gz) gzip -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
- *.tar) xz -9 -C crc64 $i ;;
- *.tbz2) bzip2 -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
- *.tgz) gzip -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
- *.zip) unzip $i -d ${i%%.*} && cd ${i%%.*} && tar cvfp - * | xz -c -9 -C crc64 &> ../${i%%.*}.tar.xz && cd .. && rm -rf ${i%%.*} ;;
- *.7z) mkdir ${i%%.*} && 7za x -o${i%%.*} $i && cd ${i%%.*} && tar cvfp - * | xz -c -9 -C crc64 &> ../${i%%.*}.tar.xz && cd .. && rm -rf ${i%%.*} ;;
- *.rar) mkdir ${i%%.*} && 7za x -o${i%%.*} $i && cd ${i%%.*} && tar cvfp - * | xz -c -9 -C crc64 &> ../${i%%.*}.tar.xz && cd .. && rm -rf ${i%%.*} ;;
- *.xz) xz -c -v -d $i | xz -c -9 -C crc64 &> ${i%%.*}.tar.xz ;;
- *) echo "\`$i': unrecognized file compression" ;;
- esac
- else
- echo "\`$i' is not a valid file"
- fi
- done
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement