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 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 equivalent to ls -s -i -z -e. As it happens, the -s option 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. If you would like some education on other software-related topics, please feel free to check out the Trailhead blog. We constantly update our library with new information and insights from the software world.
To learn about Trailhead Technology Partners and what we do, stop by our About Us page.
While there, you can get a view of the technologies we use, the values that drive us, and our experience in the industry.
And if you’d like to subscribe to our monthly newsletter, don’t hesitate to get in touch.