Where to start First steps track · 15 stages
Linux Labs

namei — permissions at every step of a path

5 min Ubuntu 24.04 · util-linux 2.39

The namei command walks a path part by part and shows the type, mode and owner of each directory down to the file.

Cheat sheet

7 commands Printable version
  • namei -l /etc/nginx/nginx.conf type, mode, owner of each part
  • namei -m /var/www/html/index.html modes only
  • namei -o /srv/app/data owner and group only
  • namei /bin/sh where symbolic links lead
  • namei -n /bin/sh don't follow links
  • namei -x /home/student mark mount points (D)
  • sudo -u www-data namei -l /srv/site/index.html as the service

Overview

To open a file, a process passes through every directory of the path, and at each one the kernel checks the x permission. ls -l shows the permissions of one part only. namei walks the whole path and prints a line for each directory and for the file:

text
student@ubuntu:~$ namei -l /etc/nginx/nginx.conf
f: /etc/nginx/nginx.conf
drwxr-xr-x root root /
drwxr-xr-x root root etc
drwxr-xr-x root root nginx
-rw-r--r-- root root nginx.conf

The first line is the path being resolved. Each following line has the type and mode (d directory, - file, l link), the owner, the group and the part's name. How to read the mode — permissions.

If it can't go further, namei prints the reason in place of the part it couldn't reach:

text
student@ubuntu:~$ namei -l /root/.bashrc
f: /root/.bashrc
drwxr-xr-x root root /
drwx------ root root root
                      .bashrc - Permission denied

The root directory gives others ---: without x you can't enter it, so .bashrc can't be checked. namei doesn't judge permissions, it only shows them. Which triple applies to an account you decide from the owner and group in the line.

Options

6

-l is -m -o -v together; it's usually all you need. Full list — man namei.

Option What it does Example
-l --long Long format — type, mode, owner and group of each part of the path. namei -l /etc/nginx/nginx.conf
-m --modes Show the mode bits of each part. namei -m /var/www/html/index.html
-o --owners Show the owner and group of each part. namei -o /srv/app/data
-n --nosymlinks Don't follow symbolic links. namei -n /bin/sh
-x --mountpoints Mark mount point directories with a D. namei -x /home/student
-v --vertical Align modes and owners in columns. namei -mov /srv/app

Nothing found. Try a shorter query.

Recipes

3

Find where a service loses access

bash
sudo -u www-data namei -l /srv/site/2026/q4/index.html

Run as the service, namei stops exactly at the part it can't pass: the line with Permission denied is the answer. Fix that part's permissions, not the file's — see chmod-chown.

Compare the parts of a path by hand

bash
ls -ld / /srv /srv/site /srv/site/2026
stat -c '%A %U:%G %n' /srv/site/2026/q4/index.html

ls with -d and stat show the same one by one — handy when there are few parts.

Where a path really leads

text
student@ubuntu:~$ namei /bin/sh
f: /bin/sh
 d /
 l bin -> usr/bin
   d usr
   d bin
 l sh -> dash
   - dash

Without -l, namei shows only types and expands each link with an indent: /bin/sh is really /usr/bin/dash. More on links — links.

Troubleshooting

4

name - No such file or directory

There's no part with that name. The lines above exist, so the typo or wrong letter case is right here. Check the previous directory's contents: ls -la dir.

name - Permission denied

The directory on the line above has no x for whoever ran namei. Look at its triple for your account (owner, group or others) and run namei as the right user with sudo -u.

namei shows everything open, but access fails

namei doesn't show ACLs, AppArmor, or the groups a process got when it started. Check getfacl path (see acl); after usermod -aG a new login or a service restart is needed — an old process keeps its old group list.

The file is 644, yet it can't be read

The file's own permissions are checked last. If any directory above is closed, the check never reaches the file — find that directory with namei -l.

See also

  • permissions — how to read rwx and which triple applies.
  • chmod-chown — fix the permissions or owner of the part you found.
  • ls — one part's permissions: ls -ld dir.
  • stat — permissions, owner and times of one file.
  • acl — extra permissions that namei doesn't show.
  • links — symbolic and hard links.
Loading…