Sunday, May 5, 2024
18
rated 0 times [  18] [ 0]  / answers: 1 / hits: 21060  / 3 Years ago, sat, june 19, 2021, 11:01:05

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.


More From » command-line

 Answers
7

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 and gnu-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 with apt-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 of find's options are multiple characters long. ps supports multiple option styles:



This version of ps accepts several kinds of options:

1 UNIX options, which may be grouped and must be preceded by a dash.
2 BSD options, which may be grouped and must not be used with a dash.
3 GNU long options, which are preceded by two dashes.


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.


[#24251] Monday, June 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ainsbeave

Total Points: 280
Total Questions: 98
Total Answers: 105

Location: Faroe Islands
Member since Sat, Aug 20, 2022
2 Years ago
;