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.

Some GNU and GNU-like tools seem to accept options in a combined manner, e.g. foo -hgcf instead of foo -h -g -c -f.

An example is tar, as in tar cXbf keepout 20 archive.shar *.txt instead of tar -c -b 20 -X keepout -f archive.tar *.txt.

I was under the impression that this "compressed" or "short" style of specifying arguments had a name. Does anyone know what it's called, how I can learn more about it, and how to find out if a tool supports it?

share|improve this question
4  
perl's Getopt::Long calls it "bundling". –  jordanm Mar 27 '13 at 17:31
    
The tar example is different because it groups all of the options together, whereas the conventional style does not allow options that have arguments to be grouped together. You couldn't do foo -hxgczf 10 12 in place of foo -h -x 10 -g -c -z 12 -f - that's something only tar does (well, i think there are a handful of other programs that do it too) –  Random832 Mar 27 '13 at 19:56
    
tar(1) is a particularly bad example, as it has its own, very idiosyncratic flag parsing. Another egregious outlier is sort(1). There are surely others... –  vonbrand Mar 27 '13 at 21:21
add comment

2 Answers

In traditional Unix, options were one letter, like ls -l or ls -d. In some cases the option would take an argument, as in cut -d: -f1 /etc/passwd (-d (delimiter) with value :, -f (fields to select) with value 1). Where the options didn't take arguments, instead of ls -l -d -F /tmp/* you can write ls -ldF /tmp/*. Some commands take options starting with +, like more +10 file starts more(1) on line 10 of file.

I believe it was the GNU project around '87 or so who introduced the idea of long options, like cut --delimiter=: --fields=1 /etc/passwd means the same as the cryptic command above in GNU's cut. This gives quite more readable options, and works around there being only 62 letters and digits, which is much too few options for e.g. ls(1)... thus we have gcc -c -O2 --fomit-frame-pointer xxx.c and such.

Some heretic commands use long options starting with just -, like convert -adjoin -authenticate passwd some.jpg graphic.gif files.png -o here.pdf (from ImageMagick, the -adjoin places the images together, the -authenticate takes a password; this is just smashed together from the manual page's options list, this combination might make no sense).

Many commands (but not all, and it depends on what Unix flavor is your poison) take -- to mean "following isn't options anymore, even if it looks like options", so with GNU's rm(1) you can get rid of the -rf file commonly created as a stupid prank by rm -- -rf.

share|improve this answer
    
find seems like another good example of such a heretic command. –  Michael Kjörling Mar 27 '13 at 20:19
    
This is a lot of useful info that seems to miss answering any of the actual questions that were asked –  Michael Mrozek Mar 27 '13 at 21:14
    
@MichaelMrozek, oops... never wondered what the smashing several flags together might be called, just used it as a nice shortcut since way back when... –  vonbrand Mar 27 '13 at 21:18
add comment

In C see getopt_long and in bash look for getopts

share|improve this answer
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.