I want to get a list of all directory permissions from current folder to /
. For example, for the directory: /var/lib/program/subfolder
, I want an output such as:
$ pwd
/var/lib/program/subfolder
$ magic_ls_-l_command somefile
drwxr-xr-x 10 root root 4096 May 15 20:20 var
drwxr-xr-x 10 root root 4096 May 15 20:20 lib
drwxrwxr-x 10 root user 4096 May 16 20:21 program
drwxrwxr-x 10 root user 4096 May 16 20:21 subfolder
-rwxrwxr-- 1 root user 4096 May 16 20:22 somefile
I don't care about the order (from /var
to /subfolder
or the other way around), the number of hard links or even the date. I just wrote them down to emulate the ls -l
output. Also, I don't care how each filename in printed (/var
and /lib
, var
and lib
, or /var
and /var/lib
). I'm just interested in the ownership of each file/directory in the path from the choosen file or pwd
to /
.
In case I should install some program, I'm under Ubuntu 20.04.
This question has already been answered in superuser.com (I don't know if I can mark a question from one site as duplicate from another). The solution is as simple as writing (assuming I am in the same directory as the target filename):
$ namei -l $(pwd)/somefile ## or `namei -l $(realpath -s somefile)`
Because of -l
, it lists basic permissions in long format for each parent directory.
I have to use pwd
/realpath
because namei
doesn't resolve relative paths. If I'm not in the target directory, just write the full path.