Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have two environments: Mac and Linux.

I wonder about the command:

it can show just 2 lines of text if I invoke it like so:

vim --version | head -2

I saw this online and ran to the page to learn more only to discover that neither the nor the pages have any information that I could decipher describing the possibility of using -2 directly to get just 2 lines of text from .

So my questions are:

  • am I reading the man pages wrong?
  • if so, what indicates the possibility of specifying -2 directly?
  • if not, is it common for recognised options not to be explicitly outlined in the page?
  • if not in , where should I look for full disclosure on a command's options?
  • are there many other convenient features like this, which objectively make much nicer and direct to use, that I am oblivious to and can't learn about by studying -h output and/or a page?

Mac

OS X v10.8.3 (build 12D78)


Linux

GNU/Linux (kernel 3.5.0-25-generic) Ubuntu 12.10

GNU coreutils 8.12.197-032bb


share|improve this question
1  
Hiya, am not sure I'm understanding your question clearly. If you have ten lines of stdin text and pipe it to head i.e. # cat somefile.txt | head -n 2 It should spit out the first two lines of somefile.txt (btw, -2 may work, but -n is the actual argument to specify the number of lines, while -c specifies the number of bytes.) –  Stephan Apr 2 '13 at 21:17
1  
head -2 is synonym to head -n 2, why? Where does it say so in the manual? head -3 is synonym to head -n 3, etc. This being the case but not being explicitly documented has a feel of "black magic"/"secret lore".. ;) –  Robottinosino Apr 2 '13 at 21:18
    
At least you'll get the full disclosure by reading the source, Luke. –  ott-- Apr 2 '13 at 21:21
    
And by doing so, succumb to the hopelessness of the dev/user divide, plunging into a life of pessimism and psycho-active tablets. There must be hope beyond browsing the source! –  Robottinosino Apr 2 '13 at 21:22
add comment

1 Answer

up vote 3 down vote accepted

Essentially, you've found the backwards compatibility flags (which, to be honest, I had never known existed.)

From the man page:

SEE ALSO
       The  full documentation for head is maintained as a Texinfo manual.  If the info and head programs
       are properly installed at your site, the command

              info coreutils 'head invocation'

At the bottom of the info coreutils page:

For compatibility `head' also supports an obsolete option syntax
`-COUNTOPTIONS', which is recognized only if it is specified first.
COUNT is a decimal number optionally followed by a size letter (`b',
`k', `m') as in `-c', or `l' to mean count by lines, or other option
letters (`cqv').  Scripts intended for standard hosts should use `-c
COUNT' or `-n COUNT' instead.  If your script must also run on hosts
that support only the obsolete syntax, it is usually simpler to avoid
`head', e.g., by using `sed 5q' instead of `head -5'.

An exit status of zero indicates success, and a nonzero value indicates failure.
share|improve this answer
1  
So the answer to one of the points above is: sometimes look into the info of the command after reading the --help and man.. –  Robottinosino Apr 2 '13 at 21:37
    
yep; especially if the bottom of the man page suggests it ;) –  Stephan Apr 2 '13 at 21:40
    
I guess another point to learn is: some options fall out of fashion, get deprecated and are actively hidden/deprecated so that new users (like me) will avoid them. You know what I think would be better than this hiding (not putting in plain sight) approach? Just show the option and say: don't use this - it may not be there in a future version. I would have been less confused. Probably just me though. –  Robottinosino Apr 2 '13 at 21:47
    
Thanks for answering my question, you also taught me some more in the process, I appreciate it. –  Robottinosino Apr 2 '13 at 21:48
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.