I was working my way through a primer on Shell (Bash) Scripting and had the following doubt :
I came across the
ls
commandThe
man
page ofls
lists a few use cases as :
ls -a
ls --block-size='M'
My Question :
- What is the difference in
-
and--
?- Why are there 2 nomenclatures used ?
- What is the motivation behind it ?
Long-form (--foo
) options are a GNU extension -- something present in GNU ls
, but not present at all in the POSIX standard setting requirements for UNIX tools, so other versions of ls
are not obliged to support these options. The entire word (foo
) is meaningful in this case. This nomenclature was added more recently, and is more expressive than the short form (and doesn't have namespace limitations).
Short-form options (-al
) are, at least in form, standardized (though extensions can add new ones). They're handled character by character, one letter at a time -- so -al
means -a
(show hidden files) and -l
(long output), rather than having -al
have its own meaning in this case. This is the original syntax for UNIX command-line options, and is thus supported not only for terseness but also for backwards compatibility.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With