I often see a single dash -
or double dash --
followed by linux commands or other installed linux programs.
What are the differences between single dash and double dashes?
Is it just about abbreviation? For example, -v
means --verbose
most of the time.
Best Answer
It is a matter of convention. POSIX standard programs usually only have single character options, and they're all prefixed with a single hyphen. The longer versions are a GNU improvement for clarity, as far as I can tell, and usually are prefixed with double hyphens. You can see this in the libraries and programs used to parse options -
getopt
andgnu-getopt
respectively. Non-GNU and non-POSIX-compliant programs may do something else altogether. Note that you really can't be sure that the long form of an argument may be the same from program to program.-f
usually means--force
, but not withapt-get install
(common misconception).-v
may mean version - usually, or--verbose
, and so on. Check the man pages or other documentation to be sure. Also have a look at the Wikipedia article on getopt. All this predates Linux by a decade or more.dd
is an example of a POSIX standard utility which doesn't have any hyphenated options at all.find
is the classic example of a POSIX standard utility that has word options with single hyphens - nearly all offind
's options are multiple characters long.ps
supports multiple option styles:GNU
tar
also supports multiple option styles.As a matter of usage, prefer the long options in scripts if you can be sure that the scripts will be run in compatible environments - the improvement in clarity is a blessing when debugging. For portability, the short options are preferred.