What's the Difference Betwen "-" and "--" Options in Shell?

In shell commands, it is a common convention to use:

  • A single hyphen (-) to specify a single character flag (or a short option), and;
  • A double hyphen (--) is used to specify a multi-character option.

For example, to list all files (including the ones that start with .), you would typically use the ls shell command with the -a flag or the --all option, like so:

ls -a
ls --all

Using a single hyphen you can specify multiple single-character flags in one go. However, with double hyphens you can only specify a single multi-character option in one go.

For example, to list all files (including the ones that start with .) and print the allocated size of each file (in blocks) you would use the ls shell command like so:

ls -as
ls --all --size

Some shell commands and utilities also allow a double hyphen on its own (i.e. without any option specified). This is also sometimes referred to as "non-option argument". It is typically used to indicate that whatever follows should be processed/interpreted as an argument and not as an option.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.