What it does
"Permission denied" often comes from a directory higher up in the path, not from the file. namei -l PATH lists each part of the path with its mode, owner and group, so you see at once where an x is missing. It also follows symbolic links and shows where they point.
How to write it
namei [OPTION]... PATHNAME...Options 9
Most used
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Check the whole path
namei -l /srv/sales/plan.txt f: /srv/sales/plan.txt dr-xr-xr-x root root / drwxr-xr-x root root srv drwxrws--T root sales sales -rw-r--r-- anna sales plan.txtOthers have no x on sales: they cannot reach plan.txt.
2Find where a link points
namei /etc/localtime f: /etc/localtime d / d etc l localtime -> ../usr/share/zoneinfo/Europe/AmsterdamFollows every link to the real file.
3Debug a web server 403
namei -l /var/www/html/app/index.htmlThe apache user needs x on every directory and r on the file.
4Show SELinux labels on the way
namei -Z /var/www/html/index.htmlNext step after the modes: the SELinux types.
5Show mount points in the path
namei -x /home/lisa/dataD marks a directory where another file system is mounted.
6Only modes, lined up
namei -mv /etc/ssh/sshd_configShort view.
7Do not follow links
namei -n /usr/bin/python3Shows the link itself only.
8Check an NFS home path
namei -l /home/lisa/projectsA root_squash export or a wrong mode on the mount point shows up here.
9Check a path for another user
su - carol -c 'namei -l /data/sales/bob.txt'Run it as the user who has the problem.
10Find a broken link
namei /opt/app/current"No such file or directory" shows which link target is missing.
Nothing matches this filter.
Exit codes
0 :: Done. 1 :: Error (for example a part of the path does not exist).