[colug-432] show path stuff

Rick Hornsby richardjhornsby at gmail.com
Fri Oct 30 12:36:06 EDT 2015


> On Oct 30, 2015, at 11:01, jep200404 at columbus.rr.com wrote:
> 
> What's a better way than the following code 
> of doing ls -ld for a file and all of its parent directories?

This sort of maybe feels like a job for tree:

$ tree --prune -FpP '70-persistent-net.rules' /etc
/etc
└── [drwxr-xr-x]  udev/
    └── [drwxr-xr-x]  rules.d/
        └── [-rw-r--r--]  70-persistent-net.rules

but does not give you the permissions for the root directory (/etc) and may match more than one file in the tree?

Poking around on the interwebs, found a command I didn't know existed - namei - which seems to do exactly what you want:

$ namei -mo /etc/udev/rules.d/70-persistent-net.rules
f: /etc/udev/rules.d/70-persistent-net.rules
 drwxr-xr-x root root /
 drwxr-xr-x root root etc
 drwxr-xr-x root root udev
 drwxr-xr-x root root rules.d
 -rw-r--r-- root root 70-persistent-net.rules





> 
>    [sb at dojo ~]$ f=/etc/udev/rules.d/70-persistent-ipoib.rules 
>    [sb at dojo ~]$ while [ "x$f" != "x" ]; do ls -ld "$f";f=`echo "$f" | sed -e 's%/[^/]*$%%'`;done
>    -rw-r--r--. 1 root root 709 Mar  6  2015 /etc/udev/rules.d/70-persistent-ipoib.rules
>    drwxr-xr-x. 2 root root 38 Jun 23 19:48 /etc/udev/rules.d
>    drwxr-xr-x. 3 root root 51 Jul  1 13:30 /etc/udev
>    drwxr-xr-x. 146 root root 12288 Oct 23 15:18 /etc
>    [sb at dojo ~]$ 
> 
> _______________________________________________
> colug-432 mailing list
> colug-432 at colug.net
> http://lists.colug.net/mailman/listinfo/colug-432




More information about the colug-432 mailing list