Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks. "tar -xzvf $1" works. –  Video Gone Feb 25 '13 at 4:12
add comment

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.

share|improve this answer
1  
Hi, welcome to AskUbuntu.com. I like your answer better than the accepted one because I feel it is a little more elegant to use an alias for this than starting a separate shell, but could you rewrite your answer to make it a bit clearer for the asker? –  Aaron D Feb 25 '13 at 7:02
    
the weakness of alias though is that it only works in the shell, while having an actual script in the PATH will work everywhere else. Though that could be a strength as well. –  Lie Ryan Feb 25 '13 at 9:48
    
This situation is ideally suited for an alias. It's true that aliases only work in a shell, but I'd be quite surprised if anyone needed a simple shortcut like this anywhere except a shell. –  Scott Severance Feb 25 '13 at 10:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.