Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In this command line sequence I use a *.sh wildcard to restore some files. I got three hits. Knowing that there must be more, I typed in the whole name. For example: I was able to restore an additional file. How could the wildcard have messed up?

My .tgz archive is on a hard disk; not optical medium. I use bash on my Ubuntu 10.10.

b@maui:~$ tar xvpfz backup2011Sep06T0000.tgz ./javawork/Trader1/*.sh
b@maui:~$ tar xvpfz backup2011Sep06T0000.tgz ./javawork/Trader1/
share|improve this question
up vote 2 down vote accepted

Your wildcard expands what is already on disk, not what is inside the archive (tgz).

share|improve this answer

when you do:

tar xvpfz backup2011Sep06T0000.tgz ./javawork/Trader1/*.sh

the *.sh is expanded by shell (assuming any ./javawork/Trader1/*.sh exists). So, tar will be executed by shell as:

tar xvpfz backup2011Sep06T0000.tgz ./javawork/Trader1/ ./javawork/Trader1/ ./javawork/Trader1/

If you want to pass wildcard to the tar, to say "please extract me only those files" you need to single-quote it and add --wildcards option:

tar xvpfz backup2011Sep06T0000.tgz --wildcards './javawork/Trader1/*.sh'
share|improve this answer
I don't understand this answer. The wildcard *.sh failed to extract Joakim Elofsson's answer makes more sense but since it got fewer votes I'm not sure it's right. – H2ONaCl Sep 25 '11 at 16:16
The * must be interpreted by shell or by tar. Shell is not able to expand it correctly because to do it it will have to understand the tar file format. So you have to say shell - do not try to expand it (you are too stupid) - pass this * to tar, and say to tar - "hey tar, please expand widlcards on base of archive contents". – Michał Šrajer Sep 25 '11 at 16:21
my answer says about the same as this, but lacks the solution – Joakim Elofsson Oct 5 '11 at 8:59
Double quotes work as well, it doesn't need to be single quotes. – Daniel Beck May 4 '12 at 12:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .