Is there a namei utility in FreeBSD?
Trond Endrestøl
Trond.Endrestol at fagskolen.gjovik.no
Wed Mar 8 08:24:08 UTC 2017
On Mon, 6 Mar 2017 11:43-0500, James E Keenan wrote:
> On 03/06/2017 11:02 AM, Anton Yuzhaninov wrote:
> > On 03/06/17 09:12, James E Keenan wrote:
> > > In Linux, there is a userland utility 'namei' which enables a user to
> > > "follow a pathname until a terminal point is found". Invoking it on,
> > > say, a symlink produces output like this:
> >
> > If you need to find a target of symlink (or symlink chain) you can use
> > realpath(1).
>
> Thanks for mentioning that. However, while the example I gave was that of a
> symlink, and while both namei and realpath are good for displaying information
> about symlinks, my central question was whether there was an equivalent to
> namei in FreeBSD. namei identifies the nature of each component in the
> resolved path; realpath does not.
I couldn't resist creating my own version of namei(1). This one is BSD
two-clause licensed, and I swear I only looked at the two URLs
mentioned in the comments and the many man pages of FreeBSD.
http://ximalas.info/~trond/namei/c/namei.c
The code is a mess and I don't know if the output matches the original
beyond what was presented in this thread. Bugs are probably in
abundance, and the -v flag isn't implemented yet.
The code does work to some extent:
$ namei /etc/rc.d/local_unbound
f: = /etc/rc.d/local_unbound
d /
d etc
d rc.d
- local_unbound
$ namei /sys/amd64/conf/GENERIC
f: = /sys/amd64/conf/GENERIC
d /
l sys -> usr/src/sys
d usr
d src
d sys
d amd64
d conf
- GENERIC
$ namei -l /sys/i386/conf/GENERIC
f: = /sys/i386/conf/GENERIC
drwxr-xr-x root wheel /
lrwxr-xr-x root wheel sys -> usr/src/sys
drwxr-xr-x root wheel usr
drwxr-xr-x root wheel src
drwxr-xr-x root wheel sys
drwxr-xr-x root wheel i386
drwxr-xr-x root wheel conf
-rw-r--r-- root wheel GENERIC
Happy hacking.
--
+-------------------------------+------------------------------------+
| Vennlig hilsen, | Best regards, |
| Trond Endrestøl, | Trond Endrestøl, |
| IT-ansvarlig, | System administrator, |
| Fagskolen Innlandet, | Gjøvik Technical College, Norway, |
| tlf. mob. 952 62 567, | Cellular...: +47 952 62 567, |
| sentralbord 61 14 54 00. | Switchboard: +47 61 14 54 00. |
+-------------------------------+------------------------------------+
More information about the freebsd-questions
mailing list