Skip to content

bash - enhanced compress and decompress

Again two functions you can add alias for. The first function provides a wrapper for the task to create tar.gz file.

If you provide only one argument (like a filename or a directory), the function creates a $name.tar.gz file from the first argument. If you provide more the one argument, the function uses the first argument as name of the *.tar.gz file and all others as files/directories to compress.

####
# compress given directories into tar.gz
#
# @author stev leibelt
# @since 2013-02-02
####
function net_bazzline_compress ()
{
  if [[ $# -lt 1 ]]; then
    echo 'No valid arguments supplied.'

    exit 1
  fi

  FILENAME_TAR="$1".tar.gz

  if [[ $# -gt 1 ]]; then
    shift
  fi

  tar -zcf "$FILENAME_TAR" "[email protected]"
}

The second function provides a wrapper to get the files of a *.tar.gz file.

If you provide one argument, the functions is using this as the *.tar.gz filename. If you provide two arguments, the second argument is used as output directory.

####
# compress given directories into tar.gz
#
# @author stev leibelt
# @since 2013-02-02
####
function net_bazzline_decompress ()
{
  if [[ $# -lt 1 ]]; then
    echo 'No valid arguments supplied.'
    echo 'Try net_bazzline_decompress $nameOfCompressedFile [$pathToDecompress]'

    exit 1
  fi

  if [[ $# -eq 1 ]]; then
    tar -zxf "$1"
  else
    tar -zxf "$1" -C "$2"
  fi
}

As general, they are also in my shell function file available on github.com.

Translate to de es fr it pt ja

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Markdown format allowed
Form options