#Bash 的 namei 命令
namei [OPTION]... PATH
功能
逐级访问路径并显示其信息。
类型
可执行文件(/usr/bin/namei),属于 util-linux。
参数
OPTION选项:-l,--long- 使用长格式输出;等价于-m -o -v-m,--modes- 打印文件权限-n,--nosymlinks- 不跟随符号链接-o,--owners- 打印文件的所有者-v,--vertical- 垂直对齐-x,--mountpoints- 作为挂载点的目录显示为D而不是d-Z,--context- 显示安全上下文-h,--help- 显示帮助-V,--version- 显示版本
FILE- 要判断的文件
#文件类型标识
f:- 正在解析的路径d- 目录l- 符号链接s- socketb- 块设备c- 字符设备p- FIFO (命名管道)-- 普通文件?- 错误
#示例
检查路径错误的具体位置
$ namei /home/user1/dir/file # 检查 /home/user1/dir/file
f: /var/www/html/dasdaxasds
d /
d home
d user1
dir - No such file or directory
检查权限错误的具体位置
$ namei /home/user2/dir/file # 检查 /home/user2/dir/file
f: /home/user2/dir/file
d /
d home
d user2
dir - Permission denied
调试 Web 服务访问失败的原因
$ sudo -u www-data namei /var/www/html/index.html # 以 www-data 用户的权限检查 /var/www/html/index.html
f: /var/www/html/index.html
d /
d var
d www
html - Permission denied
#推荐阅读
#手册
NAMEI(1) User Commands NAMEI(1)
NAME
namei - follow a pathname until a terminal point is found
SYNOPSIS
namei [options] pathname...
DESCRIPTION
namei interprets its arguments as pathnames to any type of Unix file
(symlinks, files, directories, and so forth). namei then follows each
pathname until an endpoint is found (a file, a directory, a device
node, etc). If it finds a symbolic link, it shows the link, and starts
following it, indenting the output to show the context.
This program is useful for finding "too many levels of symbolic links"
problems.
For each line of output, namei uses the following characters to
identify the file type found:
f: = the pathname currently being resolved
d = directory
l = symbolic link (both the link and its contents are output)
s = socket
b = block device
c = character device
p = FIFO (named pipe)
- = regular file
? = an error of some kind
namei prints an informative message when the maximum number of symbolic
links this system can have has been exceeded.
OPTIONS
-l, --long
Use the long listing format (same as -m -o -v).
-m, --modes
Show the mode bits of each file type in the style of ls(1), for
example 'rwxr-xr-x'.
-n, --nosymlinks
Don’t follow symlinks.
-o, --owners
Show owner and group name of each file.
-v, --vertical
Vertically align the modes and owners.
-x, --mountpoints
Show mountpoint directories with a 'D' rather than a 'd'.
-Z, --context
Show security context of the file or "?" if not available. The
support for security contexts is optional and does not have to be
compiled to the namei binary.
-h, --help
Display help text and exit.
-V, --version
Print version and exit.
BUGS
To be discovered.
AUTHORS
The original namei program was written by Roger Southwick
<rogers@amadeus.wr.tek.com>.
The program was rewritten by Karel Zak Karel Zak <kzak@redhat.com>.
SEE ALSO
ls(1), stat(1), symlink(7)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The namei command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-11-21 NAMEI(1)