Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

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/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'
share|improve this answer
    
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. –  broiyan 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

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.