Bash – Why doesn’t the command “ ls “*” ” show anything

bashlswildcards

 ls "*"

This shows nothing in my directory. Why?

Isn't * a wildcard that will show everything?

Best Answer

When it's in double quotes the * doesn't get treated as a glob, and so doesn't get expanded. So you're asking ls to list a file named *, which probably doesn't exist.

To see all the files, you could run ls without any arguments as it's default behavior is to show you all the files in the current directory. If you wanted to pass all the files as arguments to ls for some reason, just remove the quotes so you run

ls *

but that's really similar to

ls

except that if you have a lot of files * might expand to pass too many arguments to ls, and also ls * will show the contents of directories while ls by itself will just show that the directories are in the current directory without descending into them.

Related Question