This question already has an answer here:

I was looking for command to print only directory names in linux. I came across this novel syntax, where we can put two hyphens adjacent without any word.

ls -ld -- */

What is the meaning of this double hyphen (--) in this command and in general in linux commands?

marked as duplicate by muru, Kusalananda linux Apr 6 at 7:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


"--" is used to mark the end of options and thus the beginning of arguments. It tells the command to treat everything following it as arguments and not as options, even if something may look like an option. This is used in several commands, not just ls.

This prevent the command from choking on arguments (eg. filenames) that begins with a hyphen (-) or two (--), which else would cause an error (no such option) or unpredictable result (if the hyphened argument actually is a valid option), because the command would try to interpret it as an option (and not as an argument).

For example, lets say one of your arguments is a file with a newspaper article:

-No Collusion, President exclaims - Washington Post.html

A preceding "--" will prevent the "-No" from being treated as an option.

This is especially important when using jokers (*) as in your example, because you'll never know beforehand if one or more of all the files from several sub-directories may begin with a hyphen.

  • one or more of all the files from several sub-directories may begin with a hyphen: should not matter because they will be expanded subdirname/--foobar anyway and thus not have leading dashes? – xenoid Apr 6 at 7:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.