2

ls -d */ runs fine in all other directories that I tried, but in one specifically, I get this:

ls: invalid option -- '/'
Try 'ls --help' for more information.

I pasted the command in the terminal, so, it's exactly the same in both cases.

Quora Feans
  • 3,866

1 Answers1

4

You appear to have a directory named -, which ls is trying to parse as a marking series of options (or switches):

$ mkdir -- -
$ ls -d */
ls: unknown option -- /
$ -ls -d -- */
-/

Many core tools take a special switch, --, which means "No more switches; anything further is a normal argument".

Be wary of wildcards' use:

$ touch -- foo -i
$ ls
-i    foo
$ ls *
2251799814054385 foo

Just imagine the chaos that might ensue if you were using rm and there were a file called -fr in your current working directory.

DopeGhoti
  • 76,081