I put together a script to do some file operations for me. I am using the wild card operator *
to apply functions to all files of a type, but there is one thing I don't get. I can unzip
all files in a folder like this
unzip "*".zip
However, to remove all zip files afterward, I need to do
rm *.zip
That is, it does not want the quotation marks. The unzip, on the other hand, does not work if I just give it the * (gives me a warning that "files were not matched").
Why is this different? To me, this seems like the exact same operation. Or am I using the wild card incorrectly?
Introductions to the wild card in Unix do not really go into this, and I could not locate anything in the rm
or zip
docs.
I am using the terminal on a Mac (Yosemite).
Best Answer
You've explained the situation very well. The final piece to the puzzle is that
unzip
can handle wildcards itself:http://www.info-zip.org/mans/unzip.html
By quoting the * wildcard, you prevented your shell from expanding it, so that
unzip
sees the wildcard and deals with expanding it according to its own logic.rm
, by contrast, does not support wildcards on its own, so attempting to quote a wildcard will instructrm
to look for a literal asterisk in the filename instead.The reason that
unzip *.zip
does not work is thatunzip
's syntax simply does not allow for multiple zip files; if there are multiple parameters, it expects the 2nd and subsequent ones to be files in the archive: