A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

sudo doesn't list files properly

Problem:

You can list a directory using sudo:
$ sudo ls /var/log/apache/
access_log  error_log

But you can't list files with a wildcard using sudo:
$ sudo ls /var/log/apache/*_log
ls: cannot access /var/log/apache/*_log: No such file or directory

Solution:

Ensure parameter expansion happens in the shell run by sudo, not in the user's shell:
$ sudo bash -c 'ls /var/log/apache/*_log'

(source)