Ricardo Iglesias
Ricardo Iglesias

Reputation: 655

ls - Not working in certain directories

Good afternoon, I recently downloaded this .bash_profile setup, but I'm running into a small issue when running the ls command in Terminal (Mac OS X - Sierra, 10.12.6).

Error 1

ls: illegal option -- - usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

As you can see, I have no aliases, and ls is where it should be (at least I hope).

What's going on here? Anything I should do to try to remedy this situation?

Upvotes: 2

Views: 8861

Answers (1)

rodrigo
rodrigo

Reputation: 98436

The problem is in how * works in the shell.

Some people think that when you write ls * the shell will run ls passing the wildcard and that command will list all the files. But actually it is the shell that expands the * into a list of all the files and passes them to ls.

TL;DR; you have a directory name that starts with -! (I think that it is named just -). So when you run ls -d */ it is expanded to something like ls -d -/ bar/ muz/ .... You can see the actual expansion with echo ls -d */

Solution: write ls -d -- */. The -- will tell the command not to interpret any further command starting with - as an option, but as a file name.

Upvotes: 4

Related Questions