centos@ip-10-0-5-4 ~ $ sudo ls -l /var/solr/data/new_core/_default/*
zsh: no matches found: /var/solr/data/new_core/_default/*
centos@ip-10-0-5-4 ~ $ sudo ls -l /var/solr/data/new_core/_default/
total 4
drwxr-xr-x. 3 root root 4096 Mar 28 07:34 conf

- 333,661

- 31
2 Answers
The *
is expanded by the shell before sudo
is invoked. If you don't have access to that directory, the zsh
shell will complain with "no matches found". If the NOMATCH
shell option is unset in the zsh
shell, the shell would have left the pattern unexpanded and ls
would instead generate a "no such file or directory" error (unless there was something with the literal name *
in that directory). With NOMATCH
set, which it is by default, sudo ls
would not even be invoked.
You may do this instead:
sudo sh -c 'ls -l /var/solr/data/new_core/_default/*'
This prevents the current shell from expanding the *
and instead invokes sh
with the command line that you want to execute as root.

- 333,661
In first case :
access right prevent shell(*) expansion of
/var/solr/data/new_core/_default/*
when your arecentos
.command expand then as/var/solr/data/new_core/_default/*
in first case.there is no*
file or dir in/var/solr/data/new_core/_default/
, hence theno match found
.
In second case, ls find file and list them.
(*) this is the Filename Expansion
from zsh expansion (see man zshexpn
).
FILENAME GENERATION
If a word contains an unquoted instance of one of the characters `*', ...
The word is replaced with a list of sorted filenames that match the pattern.
as you are centos
before sudo
zsh could not access dir (e.g. file conf
), hence the no match found
.
ls
.sudo
andls
are not run here. They would be with that one*
file if usingbash
without thefailglob
option or most other Bourne-like shells (a behaviour that can be considered as a bug). – Stéphane Chazelas Mar 28 '18 at 13:06*
is cause of problème. – Archemar Mar 28 '18 at 14:14*
in that directory, with Bourne/ksh/bash
(withoutfailglob
), you wouldn't get an error and you would be mislead into thinking that it's the only file there. See also Why is nullglob not default? – Stéphane Chazelas Mar 28 '18 at 14:16