Tar Wild Card Interpretationby: Tony LawrenceTar wild card interpretation I had this email earlier this week: I am trying to restore a file "\GL050". Note that she is using Microlite Edge (http://aplawrence.com/Reviews/supertars.html), but that's really unimportant: you can observe the problem with tar. $ cd /tmp We know have a tar file (test.tar) containing the problem file. Let's try restoring it as she did: $ tar xvf test.tar foo/\\filewithbackslash Our wildcards look like they should work: $ echo "foo/\\filewithbackslash" At this point you may be saying "Are you crazy? Both those tar's work - with or without the quotes!" And someone else would retort "Are YOU nuts?? No they don't!" Who is nuts or not nuts has to be decided by some other method. Whether or not your tar happily works or complains as shown above simply depends upon how it handles wildcards and whether or not it gets to see them. The complaining tar above identifies itself as "(GNU tar) 1.14" and was executed on Mac OS X 10.4.5. A non-complaining tar on a RedHat Linux systems says that it is "(GNU tar) 1.13.25". Isn't that odd: the newer version seems to work "incorrectly". There's an interesting section of the "info tar" for the 1.13.25 version: There are some discussions floating in the air and asking for Info on the Mac version lacks that paragraph - though it still strongly implies that our syntax should have worked: "Globbing" is the operation by which "wildcard" characters, `*' or `?' That seems pretty plain, doesn't it? But it sure doesn't work as advertised. Hold on, someone in the back is waving their arm frantically. They have a question. What's that? A little louder, please. Oh, yes.. the shell *does* expand wildcards. If it can. When it cannot, or when we prevent it, it's tar's responsibility entirely. Both man pages take note of that: The distinction between file names and archive member names is Not sufficient on the Mac, though. Another interesting anomaly: although the Mac man page doesn't mention it, the changelog of the .14 release mentions some new flags, including: --wildcards Turns out that the older version groks those flags too, and adding them doesn't help the Mac test at all. So how do you solve this if your tar doesn't do complete wildcards? One way is to do an interactive restore where you have to affirm each file before it is restored. In this particular case (using Microlite Edge) the pattern "foo/?filewithbackslash" cuts down on the number of matches and if there is no other "?filewithbackslash" will quickly restore the desired file. GNU tar is now at 1.15, by the way: I haven't tested to see how it reacts to cases like this. I also haven't compiled 1.14 from scratch on Linux; this behaviour may be unique to the Mac instance for some reason I'm just not aware of. The usual lessons apply: the same command works differently on different platforms, things change, read the man and info pages but don't trust them, and always be prepared to experiment. © 2008 NetVisits, Inc. All rights reserved. |