What is the difference between using -
and --
in shell commands?
I've seen commands like this:
pip install -U library
and:
npm i --someOption package
Is there a difference. Are they just that --
is a full word and -
is only one letter?
Broadly, it's up to individual programs to decide what their parameters look like, so anything I say will not be universal.
However, by common convention, a double-dash is used for longer parameter names, and single-dash is used for single-character names. To take an example from the Linux ls
command:
-d, --directory
list directories themselves, not their contents
So you can use either the short or long forms in this case. Further, short parameters can often be combined... e.g. you can run ls -lrt
instead of ls -l -r -t
, which is convenient when typing in a shell.
In contrast, the longer names are often more descriptive, so while I'd rarely use them when running commands in a shell, I'd often do so when writing scripts (where long-term readability becomes a factor).
Again though, this is only convention, and not everyone follows it. Some tools don't both with a dash at all (e.g. tar xzf filename.tar.gz
), and others will use a single dash even for longer names (e.g. all of the Java command line tools).