untar filename.tr.gz to directory "filename" untar filename.tr.gz to directory "filename" shell shell

untar filename.tr.gz to directory "filename"


With Bash and GNU tar:

file=tar123.tar.gzdir=/myunzip/${file%.tar.gz}mkdir -p $dirtar -C $dir -xzf $file


tar -xzvf filename.tar.gz -C destination_directory


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.)