untar filename.tr.gz to directory "filename"
You can change directory before extracting with the -C
flag, but the directory has to exist already. (If you create file-specific directories, I strongly recommend against calling them foo.tar.gz
- the extension implies that it's an archive file but it's actually a directory. That will lead to confusion.)
With Bash and GNU tar:
file=tar123.tar.gz
dir=/myunzip/${file%.tar.gz}
mkdir -p $dir
tar -C $dir -xzf $file
tar -xzvf filename.tar.gz -C destination_directory