Why are there short and long alternatives for command line options?

11,733

Solution 1

Originally there were only single-character options. Some programs took multiple-character options, but still with a single dash. AFAIK double-dash multiple-character options come from GNU; they were introduced because they are more readable and often more memorable (and you can have more than 52 of them). Many programs now have both: short options for when you're typing on the command line and remember the character, long options for scripts or on the command line if you only remember the longer option name.

Solution 2

Another purpose I can see in having different ways of specifying parameters (short and long) is that when typing, Unix/Linux command-line folks like to have as short as possible commands. However, those can become cryptic, and if a script is written using those short versions, they can become hard to understand down the road. Using the long version can make the SAME command more readable and understandable by someone who is not the guru of this command, especially if this command is actually a locally written script as opposed to a well-known command.

Solution 3

You might guess that it is a matter of taste. When typing on the command line a short option might be preferred, especially in the case of run-together-options (e.g. ls -AL). The long options are better at conveying intent, thus you don't need to consult the man page when you read ls --almost-all --dereference.

Naturally, as you gain experience, you might learn that both of the -A and -L short options are sufficiently well known, and don't require this extra documentation. Especially in a complex command that may combine several commands in interesting ways with evaluation, redirection, etc. In such a case you might prefer brevity over documentation.

Share:
11,733

Related videos on Youtube

Ikus
Author by

Ikus

Software developer and consultant, specialising in .NET data, web and cross-platform solutions. Into clean code, usability, design and typography. Curious. Not a coffee drinker. The passion for creating useful applications for people and continuous improvement in coding has kept me in the software development business for over 20 years and counting. I started with Basic, Pascal and C++, however for the past 15 years my focus has been on C# and .NET technologies on several platforms, together with databases, JavaScript and PHP. This includes customer projects for data processing and analysis in sectors like power supply, finance, medical and manufacturing, as well as my own product ideas that I draw from everyday work. I also enjoy contributing to open source projects. In my leisure time I also like travelling and photographing the beauty of our world. Read more about me on my website.

Updated on September 17, 2022

Comments

  • Ikus
    Ikus almost 2 years

    Most unixoid commands feature short and long alternatives for command line options, like ls -a and ls --all, or ls -A and ls --almost-all. Why do those two ways exist? One is shorter to type, the other is easier to read and understand. But every time I write a shell script, I need to decide which I want to use. Is it known why the two alternatives exist? Which one was first, why was the other introduced. On DOS/Windows for example there's almost only case-insensitive one-letter options.

  • Norman Gray
    Norman Gray almost 14 years
    +1 for mentioning that long options are better for scripts, because they help document things
  • dingzhihu
    dingzhihu almost 14 years
    As for "only 52 of them": Try ls -BartSimpsonIsJustCool (or Great if you're on Solaris.
  • user712092
    user712092 over 11 years
    @AaronDigulla Is this Easter egg?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 11 years
    @user712092 No, it's a trick. Under Linux, everything after the I is the argument to the -I option, so it only makes a difference if you have a file called sJustCool in the current directory. The -BartSimpson part can be reordered, except that the S (sort by size) has to stay after the t (sort by date). Also m has no effect when n or o are present. So the command is equivalent to ls -BSainopsr, and if I haven't missed anything you can't remove another letter to achieve the same output and you can reorder these letters freely.
  • Radko Dinev
    Radko Dinev almost 10 years
    @Gilles: by the way, to be as accurate as possible, there may be 62 different short options (including digits), not 52. Consider gzip -9 filename for instance.