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.

I'm trying to create a script to extract only jpeg pictures from an archive containing many kind of files.

To do so, I tried to use:

   tar -xf MyTar.tar *.jpg

but it failed (*.jpg not found) and suggest me to use "--wildcard". So I tried

tar -xf MyTar.tar --wildcard *.jpg

I did that, but then the same error and a different warning saying to me that the option "--wildcard" is ambiguous.

I've been over the man pages for tar, but didn't find a clue about the problem.

share|improve this question

2 Answers 2

Put quotes around the wildcard like this "*.jpg" so the shell won't try expanding it and will instead pass it straight through to tar. You want tar to evaluate the wildcard, not the shell and the quotes do that.

share|improve this answer
    
Indeed I forgot to protecter the string. However, I tried but it didn't work neither. same error occurs –  AdrieanKhisbe Nov 12 '12 at 22:58
up vote 0 down vote accepted

In the end, I found then answer after a good break. The option is wildcard*s*, plural...

So the command

tar -xf MyTar.tar --wildcards "*.jpg"

did exactly what I needed.

share|improve this answer
    
(I also included the quotes as Nicole suggested" ) –  AdrieanKhisbe Nov 12 '12 at 23:11

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.