I have recently switched from bash to zsh and now when I type
ls *
It does not simply list all files in this directory, but shows a tree of two levels.
Also
rm -rf somepath/*
fails with the output zsh: no matches found:
This used to work just fine with bash. Can anyone help me to get this behaviour back?
I do have oh-my-zsh installed.
Best Answer
ls *
would have the same effect in bash. No matter what the shell is, what happens is that the shell first expands the wildcards, and then passes the result of the expansion to the command. For example, suppose the current directory contains four entries: two subdirectoriesdir1
anddir2
, and two regular filesfile1
andfile2
. Then the shell expandsls *
tols dir1 dir2 file1 file2
. Thels
command first lists the names of the arguments that are existing non-directories, then lists the contents of each directory in turn.If
ls
behaved differently in bash, either you've changed the bash configuration to turn off wildcard expansions, which would turn it off everywhere, or you've changed the meaning of thels
command to suppress the listing of directories, probably with an alias. Specifically, havingin your
~/.bashrc
would have exactly the effect you describe. If that's what you did, you can copy this line to~/.zshrc
and you'll have the same effect.The fact that
rm -rf somepath/*
has a different effect in bash and zsh whensomepath
is an empty directory is a completely different matter.In bash, if
somepath/*
doesn't match any files, then bash leaves the wildcard pattern in the command, sorm
sees the arguments-rf
andsomepath/*
.rm
tries to delete the file called*
in the directorysomepath
, and since there's no such file, this attempt fails. Since you passed the option-f
torm
, it doesn't complain about a missing file.In zsh, by default, if a wildcard doesn't match any files, zsh treats this as an error. You can change the way zsh behaves by turning off the option
nomatch
:I don't recommend this because having the shell tell you when a wildcard doesn't match is usually the preferable behavior on the command line. There's a much better way to tell zsh that in this case, an empty list is ok:
N
is a glob qualifier that says to expand to an empty list if the wildcard doesn't match any file.