3

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: goFindRanges.sh. 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
./javawork/Trader1/goReloadOp.sh
./javawork/Trader1/goReloadAudit.sh
./javawork/Trader1/goTrade.sh
b@maui:~$ tar xvpfz backup2011Sep06T0000.tgz ./javawork/Trader1/goFindRanges.sh
./javawork/Trader1/goFindRanges.sh

2 Answers 2

2

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

9

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/goReloadOp.sh ./javawork/Trader1/goReloadAudit.sh ./javawork/Trader1/goTrade.sh

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'
4
  • I don't understand this answer. The wildcard *.sh failed to extract goFindRanges.sh. Joakim Elofsson's answer makes more sense but since it got fewer votes I'm not sure it's right.
    – H2ONaCl
    Sep 25, 2011 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". Sep 25, 2011 at 16:21
  • my answer says about the same as this, but lacks the solution Oct 5, 2011 at 8:59
  • Double quotes work as well, it doesn't need to be single quotes.
    – Daniel Beck
    May 4, 2012 at 12:10

You must log in to answer this question.

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