how to select all items in zsh?

Asked by At

in bash, we can say

dnf install <some-pkg>-*


rm -rf *.jpg

but when I'm using zsh, it doesn't do anything with the star (*) character! how can I do those commands on zsh?!

2 Answers

chepner On Best Solutions

These are two different uses of globs. With dnf, you expect dnf itself to expand the pattern against the available packages. With rm, you are expecting the shell to expand the pattern against the files in the current directory and passing the resulting names to rm.

In bash, the default behavior is for a pattern that doesn't match anything to be treated as a literal string. That's why the dnf example works in bash: when there are no local files matching <some-pkg>-*, the literal string is passed to zsh.

The solution is to quote strings that you intended to be treated literally, instead of relying on your shell's treatment of unmatched patterns. The following will work as intended in both shells:

dnf install "<some-pkg>.*"
rm -rf *.jpg

In both shells, you can change how unmatched patterns are treated. To make zsh act like the bash default, use


To make bash behave like the zsh default, you could use

shopt -s failglob
Pavan On

Probably, the globbing is disabled on your zsh. Enable it using the below command in zsh:

setopt GLOB