Skip to content
Advertisement

Looking to do a simple script for compressing and decompressing a file in linux

I need to take a 7z file and uncompress it, then recompress it with zip, and I’d like to do with this with a script, what’s something quick and basic I can use? It’s centos if that would make a difference.

Advertisement

Answer

Please refer to repack-7z-files-to-zip-files-in-linux:

#!/bin/bash

TMPDIR=tempdir_$$

for x in `ls *.7z`; do
    mkdir $TMPDIR
    cd $TMPDIR
    cp ../$x .
    p7zip -d $x
    zip -r ../${x%.7z}.zip *
    cd ..
    rm -rf $TMPDIR    
done

Personally I use the 7z command on Ubuntu (p7zip-full package) that supports both both compression formats.

The complexity of your solution may also depend on whether the 7z file contains multiple files, or just a single file/tar-ball.

Advertisement