Interesting commands: Compression

Recopilation of commands of the most used compressors.

TAR.GZ

# Pack and compress:
tar czvf file.tar.gz /foo/bar/*

# Decompress and unpack:
tar xzvf file.tar.gz

# See content:
tar tzvf file.tar.gz

ZIP

# Compress:
zip file.zip /foo/files

# Decompress:
unzip file.zip

# See the content:
unzip -v file.zip

RAR

# Compress:
rar -a file.rar /foo/files

# Decompress:
Descomprimir rar -x file.rar

# See content:
rar -l file.rar

.GZ

# Compress
gzip -q file # It created a file.gz

# Decompress
gzip -d file.gz

TAR.BZ2

# Compress:
tar -c files | bzip2 > file.tar.bz2

# Decompress:
bzip2 -dc file.tar.bz2 | tar -xv

# See the content
tar jvxf file.tar.bz2

TAR

# Pack:
tar cvf file.tar /foo/bar/*

# Unpack:
tar xvf file.tar

# See content without unpack:
tar tvf file.tar

BZ2

# Compress:
bunzip2 file

# Decompress
bzip2 -d file.bz2

LHA

# Compress:
lha file.lha /foo/files

# Decompress:
lha -x file.lha

# See content:
lha -l file.lha

ZOO

# Compress:
zoo -a file.zoo /foo/files
# Decompress:

zoo -x file.zoo

# See the content
zoo -L file.zoo

zsh function

If you are using zsh and you don't want to learn all this commands, you can use this function instead.

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