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

Find out the difference between single dash and double dash syntax in a 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.


Hope you found this post useful. It was published . Please show your love and support by sharing this post.