View permission / owner of full directory tree

The command could have been:

namei -m /home/user/dir/child/file

I think you might be thinking of the tree command. For example:

$ tree -pufid apps/glassfish3/ | less
apps/glassfish3
[drwxr-xr-x saml    ]  apps/glassfish3/bin
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/bin
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/config
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/doc-files
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/annotation
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/annotation/security
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/annotation/sql
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/decorator
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/ejb
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/ejb/embeddable
...
...

The above switches do the following:

  • -p - permissions
  • -u - username/userid
  • -f - full path
  • -i - don't print indentation lines
  • -d - print directories only

References

  • tree man page

After giving it some thougth I came up with this

#!/bin/sh
l_path=$1
while [ "$l_path" != / -a "$l_path" != . ]; do
     ls -ld $l_path
     l_path=$(dirname -- "$l_path")
done

The output looks like this

-rw------- 1 tant tant 181016423 Jun 25 23:49:17 2013 /home/tant/test_file
drwxr-xr-x 85 tant tant 5632 Jul  9 19:40:11 2013 /home/tant
lrwxr-xr-x 1 root wheel 8 Sep  4 23:53:27 2012 /home -> usr/home

I hope it is ok that it is in reverse order.

Based on the comments, here's a way to list from the root downwards:

#!/bin/sh
l_path=$1
while [ "$l_path" != / -a "$l_path" != . ]; do
     ls -ld $l_path
     l_path=$(dirname -- "$l_path")
done | sed '1!G;h;$!d'