Categories
SysOps

How to inspect a path during the troubleshooting process

Inspect a path during the troubleshooting process.

Display help information for the namei utility which is a part of the util-linux package.

$ namei --help 
Usage:
 namei [options] <pathname>...

Follow a path until a terminal point is found.

Options:
 -x, --mountpoints   show mount point directories with a 'D'
 -m, --modes         show the mode bits of each file
 -o, --owners        show owner and group name of each file
 -l, --long          use a long listing format (-m -o -v) 
 -n, --nosymlinks    don't follow symlinks
 -v, --vertical      vertical align of modes and owners
 -h, --help          display this help
 -V, --version       display version

For more details see namei(1).

Follow a path to inspect ownership and permissions.

$ namei --owners /var/opt/gitlab/prometheus/prometheus.yml 
f: /var/opt/gitlab/prometheus/prometheus.yml
 d root              root /
 d root              root var
 d root              root opt
 d root              root gitlab
 d gitlab-prometheus root prometheus
 - gitlab-prometheus root prometheus.yml
$ namei --modes /var/opt/gitlab/prometheus/prometheus.yml 
f: /var/opt/gitlab/prometheus/prometheus.yml
 drwxr-xr-x /
 drwxr-xr-x var
 drwxr-xr-x opt
 drwxr-xr-x gitlab
 drwxr-x--- prometheus
 -rw-r--r-- prometheus.yml
$ namei --owners --modes /var/opt/gitlab/prometheus/prometheus.yml 
f: /var/opt/gitlab/prometheus/prometheus.yml
 drwxr-xr-x root              root /
 drwxr-xr-x root              root var
 drwxr-xr-x root              root opt
 drwxr-xr-x root              root gitlab
 drwxr-x--- gitlab-prometheus root prometheus
 -rw-r--r-- gitlab-prometheus root prometheus.yml
$ namei --long /var/opt/gitlab/prometheus/prometheus.yml 
f: /var/opt/gitlab/prometheus/prometheus.yml
drwxr-xr-x root              root /
drwxr-xr-x root              root var
drwxr-xr-x root              root opt
drwxr-xr-x root              root gitlab
drwxr-x--- gitlab-prometheus root prometheus
-rw-r--r-- gitlab-prometheus root prometheus.yml    

Follow a path to inspect symlinks.

$ namei /usr/bin/gofmt
f: /usr/bin/gofmt
 d /
 d usr
 d bin
 l gofmt -> ../lib/go-1.18/bin/gofmt
   d ..
   d lib
   d go-1.18
   d bin
   - gofmt
$ namei /usr/share/npm/npmrc 
f: /usr/share/npm/npmrc
 d /
 d usr
 d share
 l npm -> nodejs/npm
   d nodejs
   d npm
 - npmrc

Follow a path to inspect mountpoints (using D instead of d letter).

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           3.2G  2.8M  3.2G   1% /run
/dev/nvme0n1p2  468G  203G  242G  46% /
tmpfs            16G   74M   16G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/nvme0n1p1  511M  5.3M  506M   2% /boot/efi
tmpfs           3.2G  160K  3.2G   1% /run/user/1000
$ namei --mountpoints /run/user/1000/dconf/user 
f: /run/user/1000/dconf/user
 D /
 D run
 d user
 D 1000
 d dconf
 - user

Simple as that.