ztar - my wrapper on tar -z

29 June 2005   8 comments   Python, Linux

Mind That Age!

This blog post is 13 years old! Most likely, its content is outdated. Especially if it's technical.

Something I find myself doing very often is to download a .tar.gz or .tgz file that I want to unpack, but only in a subfolder. Some rather annoying gzips aren't collected in one folder so that when you unpack it lots of files are created in the current directory. Do you find yourself often doing this:

$ tar -ztvf Some-0.x.tar.gz
Some/file1.txt
Some/file2.txt
...
Some/file100.txt
$ tar -zxvf Some-0.x.tar.gz
Some/file1.txt
Some/file2.txt
...
Some/file100.txt

Or, in case they the gzip is badly organised:

$ tar -ztvf Foo-0.y.tar.gz
file1.txt
file2.txt
...
file100.txt
$ mkdir Foo; mv Foo-0.y.tar.gz Foo/; cd Foo/
$ tar -zxvf Foo-0.y.tar.gz
file1.txt
file2.txt
...
file100.txt
$ cd ..

If you feel that this is too much typing, consider my little (python) script so that you can do this:

$ ztar Some-0.x.tar.gz
Some/file1.txt
Some/file2.txt
...
Some/file100.txt
$ ztar Foo-0.y.tar.gz
Not tarred in one single folder. Create a new one?
Folder: Foo
Foo/file1.txt
Foo/file2.txt
...
Foo/file100.txt 

The ztar program is a little Python script that wraps up all of these alternatives and options into one little program. Drawback: you get used to it and all of a sudden it's not there because it's not part of the the standard bash utils.

To make this happen on your Linux system, download the file and make it executable. Stick it in your global or local bin directory and enjoy. Remember, this is not rocket science and it welcomes feedback.

Comments

Jacob

Great idea. Why didn't I think of that?

Ian Bicking

atool does this too, incidentally:

http://www.student.lu.se/~nbi98oli/atool.html

Peter Bengtsson

An interesting way for me to learn. Instead of searching for the existing solution I dabble on one and then people help me find the existing solution. Thank you Ian.

Ng Pheng Siong

$ (mkdir foo; cd foo; tar xovf ../foo-xyz.tgz)

The parens means run all commands in the same shell child process - this makes the "cd" stick for the subsequent "tar".

The shell is for scripting too.

Peter Bengtsson

that only applies if you know that you want to put it in folder.

Anonymous

Another old "copy a directory across filesystems without creating temporary files" trick, back when not everything is under / in a single filesystem...

$ tar cf - this-dir | (cd that-dir; tar xf -)

Peter Bengtsson

the usability of that one is questionably

Peter Bengtsson

here's another one that won't require approval

Your email will never ever be published


Related posts

Previous:
Zope in DevelopmentMode 26 June 2005
Next:
Porting IssueTrackerProduct to Zope 2.8.0 30 June 2005
Related by Keyword:
How much HTML is too much for optimal web performance 17 October 2018
django-pipeline and Zopfli 15 August 2018
HTMLMinifier in use on this blog now 07 August 2018
How to NOT start two servers on the same port 11 June 2018
How I found out where a bash alias was set up 09 May 2018
Related by Text:
jQuery and Highslide JS 08 January 2008
I'm back! Peterbe.com has been renewed 05 June 2005
Anti-McCain propaganda videos 12 August 2008
Ever wondered how much $87 Billion is? 04 November 2003
Guake, not Yakuake or Yeahconsole 23 January 2010