Background
I think your issue is ultimately because of these permissions on that directory:
drwxr-x--x 16 www-data root 12288 Oct 10 17:08 .
Notice that the owner (www-data
) and the group (root
) have rwx
and r-x
respectively. However notice that the other permissions are set to just --x
.
This means that you can execute commands in this directory, but you cannot read or perform listings of the contents of this directory.
Your scenario
You're some other user (not www-data
), when you run the sudo
command while in this directory. Let's call this user, UserX.
When the shell invokes this command as UserX:
$ sudo ls *.*
and returns this:
ls: cannot access *.*: No such file or directory
UserX's shell tried to expand the *.*
to any files, but because UserX cannot read any of the contents of this directory it returns nothing. You're then sending a literal *.*
to the sudo ls *.*
which fails to match any literal files named *.*
.
The same problem occurs when you attempt to perform the grep
command too. Again UserX cannot read any of the files and so you're instructing grep
to search for a literal file, *.*
, and it's finding no files by that name. Hence the messages:
cannot access .: No such file or directory
and
.: No such file or directory
Example
Say we have the following setup, like yours.
$ sudo chown nginx.root /tmp/afolder
$ sudo chmod 751 /tmp/afolder/
$ sudo ls -ld /tmp/afolder/
drwxr-x--x 2 nginx root 4096 Nov 23 04:10 /tmp/afolder/
$ sudo touch /tmp/afolder/fakefile.txt
Now let's become "UserX", in my case it's saml
:
$ id
uid=500(saml) gid=501(saml) groups=501(saml)
I can cd into the directory:
$ pwd
/tmp/afolder
But when I attempt to list the files in this directory:
$ ls *
ls: cannot access *: No such file or directory
Same problems with sudo
:
$ sudo ls -l *.*
ls: cannot access *.*: No such file or directory
Invoking a shell and protecting the expansion of the *
with single quotes can get what you want:
$ sudo bash -c 'ls -l *.*'
-rw-r--r-- 1 root root 0 Nov 23 04:14 fakefile.txt
*.*
usually expands to all files that have a dot (except the ones starting with a dot).*.* no such file
would be when there is no file with dot, or you quoted the"*"
to mean a literal asterisk instead.set -x
before running a command with a glob pattern?ls -ld .
; however, the key information that is missing is: who are you? Output ofid
. The directory is not readable to users who are notwww-data
, or who are not in group 0,root
. The directory is searchable, which means files can be accessed if you know the exact name. But the directory cannot be listed.