Could someone please explain this to me?

[rabdelaz@Linux_Desktop:/etc/apache2]$sudo ls /var/log/apache2/*.log
ls: cannot access /var/log/apache2/*.log: No such file or directory

[rabdelaz@Linux_Desktop:/etc/apache2]$sudo ls /var/log/apache2/
access.log  error.log.1      error.log.11.gz  error.log.13.gz  error.log.2.gz  error.log.4.gz  error.log.6.gz  error.log.8.gz  other_vhosts_access.log
error.log   error.log.10.gz  error.log.12.gz  error.log.14.gz  error.log.3.gz  error.log.5.gz  error.log.7.gz  error.log.9.gz  ssl_access.log

Clearly there IS such file or directory. I am confused. Is Ubuntu also confused?

1 Answer 1


Your shell will try try expand the * wildcard, before elevating the privileges of the ls command.
Because as a regular user you don't have sufficient rights to read /var/log/apache2 that expansion will fail.

Then the *.log will be passed through to sudo, but since sudo doesn't do globbing (that's a shell function) the ls will fail again as there is no file named *.log

A circumvention would be:

sudo sh -c 'ls /var/log/apache2/*.log' 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.