Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Sep 1 '09 at 4:47

This question came from our site for professional and enthusiast programmers.

    
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 –  Matthew Scharley Sep 8 '09 at 5:25
add comment

3 Answers 3

up vote 8 down vote accepted

use zip ./-

- means: read from stdin (standard input)

share|improve this answer
    
+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. –  dmckee Sep 1 '09 at 1:22
show 1 more comment

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

~/-

/home/mariusz/Desktop/-
share|improve this answer
add comment

@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.

share|improve this answer
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. –  Matthew Scharley 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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