Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Tog, Kevin Panko, Carl B, m4573r, Ƭᴇcʜιᴇ007 Dec 23 '13 at 18:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

1 Answer 1

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
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.