I can unzip a zip file contains a file named "-"

But it seems that "-" is a magic char in zip command...

How could I zip this file with zip command?

  • Escaping it might work ( \- ), although there are lots of other good examples below.
    – J. Polfer
    Sep 2 '09 at 14:03
  • Using \- will only work if the program itself supports it: this is more than likely not the case and will not do what you want Sep 8 '09 at 5:25

use zip ./-

- means: read from stdin (standard input)

  • +1, but I don't think it's an alias for stdin in case of zip.
    – hacker
    Aug 31 '09 at 8:14
  • ok, could also be the beginning of an option like -f or something. i don’t have a linux machine at hand to test/verify. nevertheless, the question was how to zip this file, not why it was not working :)
    – knittl
    Aug 31 '09 at 8:20
  • Sure, that's why +1 ;-)
    – hacker
    Aug 31 '09 at 8:28
  • :)
    – knittl
    Aug 31 '09 at 8:59
  • 1
    Careful with the word "alias" because there is a shell construct of that name. Using - to mean "read from the standard input" is a common unix command-line argument idiom, but it is not translated as such by the shell. Sep 1 '09 at 1:22

On my Uni profesor said when we have strange name of file we should use all path to file ;) example:



@knittl's answer should work, but I think the more correct answer is:

zip ... -- -

Where the plain -- says that the rest of the input is filenames. Most linux commands support this, but I'm not sure off the top of my head if zip does or not.

  • 2
    I also thought so and wanted to give an answer like this, but I've tried it with zip and it didn't work. IIRC, zip has its own processing of options and doesn't use getopt.
    – hacker
    Aug 31 '09 at 8:17
  • For shame. Oh well, this will probably be useful to someone else trying to use a different command, so I'll leave it here anyway. Aug 31 '09 at 8:22
  • Yeah, it's somewhat funny that both you and knittl made some perfectly sensible assumptions that just do not apply to zip.
    – hacker
    Aug 31 '09 at 8:29
  • 1
    The "--" option is accepted by many GNU utilities and some others on some platforms. However, it is NOT the recommended method. Prefixing -* filenames with a relative or absolute path, canonically using ./-* is most portable answer. I consider it to be the most basic technical screening question for such hands-on sysadmin positions. (Only partial credit for -- answers, full credit for ./, and extra for laughing and pointing out that it's an old FAQ --- 0 pts. for any attempt at quoting or escaping with backslash; those are DANGEROUS)!
    – Jim Dennis
    Sep 1 '09 at 6:19

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.