Ubuntu: Creating a terminal command to extract tarballs


This is pure laziness, but I'm looking to create a custom terminal command to extract tarballs - ie "targz" then a filename would extract a tar.gz tarball, and "tarbz2"... Well, guess. I followed the instructions for creating custom commands found here, and while I'm sure that worked great for that asker (who wanted a command to start a couple of things for him, which required no additional arguments or anything), it's not working for me. The "targz" file in my ~/bin reads as follows:

tar -xzvf  

What wizardry. So I type

targz putty-0.62.tar.gz  

in the terminal, and it gives me:

tar: option requires an argument -- 'f'  

Any way to make this work so I can just type "targz" then the target filename into the terminal and have it be extracted? Or, for extra sloth points, type something like "untar" then a target filename, then have it be extracted whether it's .gz or .bz2?


What you want to do is pass arguments to a shell script. Check out this link. I think you'll have your answer. As for the second part of your question, using tar -xvf will untar any file whether it's .gz, .bz2 or .xz.


you could also create an alias like this:

alias utgz='tar -zxf '  

Now issuing utgz tarball.tar.gz will extract all the files from the ta, without the overhead of going through a separate shell. As I understand it the alias just acts as a text substitution.

If you type alias at your prompt you might see something like 'ls=ls -F' and so on. so utgz tarball.tar.gz gets changed to tar -zxf tarball.tar.gz.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »