Code Snippet:

Written by Troy Howard

19 March 2013

Simple untar script that does the obvious thing and creates a directory named after the tar file, then extracts a tar in that directory. This is a handy to install in user scope to augment tar.


# cross platform absolute path function
abspath() {
  [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"

outd=`abspath ``basename $1 .tgz`` `
target=`abspath $1`

echo "extracting to $outd"
(mkdir -p $outd && cd $outd && tar -zxvf $target)

This is available as a Gist here:

Opinions? Discuss this article on Twitter ...