1

Say I have a file located at /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java.

I want to list all its parent directories in order to view their permissions in order to get something like below, so I can track down permission issues.

drwxr-xr-x  7 root     root  4096 Dec 16 17:50 java
dr-xr-xr-x  2 root     root  4096 Dec 16 17:50 bin
dr-xr-xr-x  3 root     root  4096 Dec 16 17:50 jre
drwxr-xr-x 14 root     root  2920 Dec 16 17:50 java-1.6.0-openjdk-1.6.0.0.x86_64
...

Is this possible?

1
  • 2
    @pabouk Thanks for the link, it did give me the answer I needed, which is namei -l.
    – xiankai
    Dec 19, 2013 at 9:25

1 Answer 1

5

An idea:

FILE=/usr/bin/ppmpat

until [ "$FILE" = "/" ]; do
        ls -lda $FILE
        FILE=`dirname $FILE`
done

Of course change FILE with the file you want. The order will be opposite from your request indeed (going from file to top) but eventually you can run the command through "tac" if needed ;)

My output:

-rwxr-xr-x 1 root root 22672 Oct 17  2011 /usr/bin/ppmpat
drwxr-xr-x 2 root root 114688 Dec 19 07:04 /usr/bin
drwxr-xr-x 13 root root 4096 Feb 11  2013 /usr

Or piped in "tac":

drwxr-xr-x 13 root root 4096 Feb 11  2013 /usr
drwxr-xr-x 2 root root 114688 Dec 19 07:04 /usr/bin
-rwxr-xr-x 1 root root 22672 Oct 17  2011 /usr/bin/ppmpat

Not the answer you're looking for? Browse other questions tagged .