gzip

  • Extract .tar.gz file:

    1$ tar xvzf ./file.tar.gz
    
  • Extract only one subdirectory and all its sub-content:

    1$ tar -xvzf my-archive.tar.gz --wildcards "./directory/subdirectory*"
    
  • Create a .tar.gz file:

    1$ tar cvzf file.tar.gz ./subfolder
    
  • Extract all .gz files in the current folder:

    1$ gunzip ./*.gz
    
  • Convert .tar.gz file to .tar.bz2 file:

    1$ gzip -dc archive.tar.gz | bzip2 > archive.tar.bz2
    

bzip2

  • Extract .tar.bz2 file:

    1$ tar xvjf ./file.tar.bz2
    
  • Check a .bz2 file integrity:

    1$ bzip2 --test ./file.bz2
    
  • Extract ./path/in/archive* subfolder content from all .tar.bz2 archives available in the current folder. Place the extracted content of each archive in a folder prefixed with the content- string:

    1$ for ARCHIVE in `ls *.tar.bz2`; do DEST_FOLDER=content-`echo $ARCHIVE | cut -d '.' -f 1`; mkdir $DEST_FOLDER; tar -C $DEST_FOLDER -xvjf $ARCHIVE --wildcards "./path/in/archive*"; done
    

ZIP

  • Create a .zip archive of current directory, including all sub-dirs:

    1$ zip -r archive.zip ./*
    
  • One liner to download an archive and extract its content to a target folder:

    1$ wget -O - "https://example.net/archive.zip" | tar -xz --directory /target-folder -f -
    

7-Zip

  • Create a 7-Zip archive (thanks to p7zip ) of a folder, including all sub-directories:

    1$ 7za a archive.7z ./folder
    
  • Do the same as above, but split the archive in 50 Mib volumes:

    1$ 7za a -v50m archive.7z ./folder
    

shar