//Tips tagged gzip
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
From dotfiles.org; original author unknown:

###   Handy Extract Program

extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2)   tar xvjf $1        ;;
            *.tar.gz)    tar xvzf $1     ;;
            *.bz2)       bunzip2 $1       ;;
            *.rar)       unrar x $1     ;;
            *.gz)        gunzip $1     ;;
            *.tar)       tar xvf $1        ;;
            *.tbz2)      tar xvjf $1      ;;
            *.tgz)       tar xvzf $1       ;;
            *.zip)       unzip $1     ;;
            *.Z)         uncompress $1  ;;
            *.7z)        7z x $1    ;;
            *)           echo "'$1' cannot be extracted via >extract<" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}


View Comments »



GNU tar comes with native support for gzip, bzip2, and compress (adaptive LZ, LZW). However, many other useful compression algorithms exist, but most implementations of them don't support all the file system metadata that tar does. There are two general methods to using tar with arbitrary compression programs: via an option in tar itself and via piping. The first:
tar -cf foo.tar.ext --use-compress-program generic_compression_program file1 [file2] [file3] [...]

Note that this method is not very configurable and only works with programs that compress by default and will decompress files when invoked with the "-d" option.

The second method:
tar -c file1 [file2] [file3] [...] |generic_compression_program >archive.tar.ext

This method is more versatile, but it requires a bit more shell voo-doo to work (and may not require use of stdout redirection). For instance, to make a .tar.7z archive:
tar -c list of files and directories to compress |7z a -si outfile.tar.7z

To uncompress said archive:
7z e -so infile.tar.7z |tar -x


View Comments »




Home Latest Browse Top 25 Random Hall Of Fame Contact Submit