6

I have a Zip file with a hyphen at the start of its name, let's say '- stuff.zip'

If I need to move or copy the file, this means that I need to use a double-hyphen so that the filename isn't interpreted as an option :

cp -- '- stuff.zip' '- stuff2.zip'

However, if I try to use unzip with this file, that doesn't work:

unzip -l -- '- stuff.zip'

error: -fn or any combination of -c, -l, -p, -t, -u and -v options invalid

I have tried all the combinations of simple and double quotes, backslashes, filename in variable that I could think of, and I can't make it work. I can't rename the file, as the script will run on a read-only filesystem.

One thing that does work is using find :

find -maxdepth 1 -name '- stuff.zip' -exec unzip -l {} \;

But it is very inconvenient.

Giacomo1968
  • 58,727

1 Answers1

7

Try this method of prepending - stuff.zip with ./:

unzip -l './- stuff.zip'

Or use this method that does’t need quotes — single or double — but escapes the space after the hyphen:

unzip -l ./-\ stuff.zip
Giacomo1968
  • 58,727