When you’re using a shell command, it’s common to pass options to that command using dashes–which are also called hyphens. These options can be specified with either a single dash (-) or a double dash (–). But have you ever wondered when to use one or the other: a single dash or a double dash?
$ ls --size -l $ ls -ls
It’s actually pretty simple. A single dash can be followed by any number of single-character flags, while a double dash can be followed only by a single, multi-character option. For example, if you want a listing using the ls command, and you want to include the file sizes, you can specify either of these options:
$ ls --size $ ls -s
The second one is more compact, but it gets even MORE compact when you want to specify multiple flags. Consider:
$ ls -l --size --human-readable --group-directories-first $ ls -lshg
While the two commands listed above are identical, the second one is clearly much quicker to type.
If you use the wrong type of hyphen, for example specifying ls -size instead of ls –size, you’ve probably learned this already, as the first command would be interpreted by the shell as equivalent to ls -s -i -z -e. As it happens, the -s options is the same as –size, but because there are no z or e options for the ls command, this doesn’t work.
Hopefully this little tidbit satisfies your curiosity a little, and also helps you understand just a little better what you’re doing at the command line.
Photo by n3wjack, cc-licensed