5

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.

6

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
1
  • 1
    This works perfecly, thank you.
    – user123065
    Oct 20 '20 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.