Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a system with symlinks EVERYWHERE, so given a particular directory, is there a simple way to find out what mountpoint this directory is on? Particularly interested in solaris.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can try:

df dirname

It should give the filesystem and mount point of the target of the symlink.

If you want to know the mount point and filesystem of the symlink itself:

df $(dirname /path/to/dirname)

(That's the command dirname and a dummy directory named "dirname", confusingly enough.)

share|improve this answer
    
yeah, that doesn't help much, the symlinks go forwards and backwards and there are often many ways to get to the same place. –  Stu Feb 5 '10 at 20:08
    
Did you actually try this? Because it does what you're asking in your question. Seems to work on my OpenSolaris box...but it's running everything on ZFS but I don't think that matters. –  3dinfluence Feb 5 '10 at 20:13
    
I just tested with symlinks 3 hops deep between two different zfs pools and multiple filesystems on OpenSolaris and df was properly reporting where the actual directory is. –  3dinfluence Feb 5 '10 at 20:19
    
ahhh. I tried the first bit, missed the second bit. What I didn't realize was that df does this itself. My bad. I thought you had to give it a real filesystem only. –  Stu Feb 5 '10 at 20:51
add comment

I know this provides a little more information than you requested. But you could make a simple C program using the realpath() library call. I have done this before to find out exactly where a specific file was. From there it should be a simple matter of determining the filesystem. A sample program would look like:

 /*
 * realpath - a program to find the real path
 */

 #include <limits.h>
 #include <stdlib.h>
 #include        <stdio.h>


 main(int argc, char **argv, char **envp)
 {
    void exit();
    char realx[10000];

    printf("\nORIGINAL PATH:\t%s\n",argv[1]);

    printf("Real PATH:\t%s\n",realpath(argv[1],realx));

    exit(0);

 }
share|improve this answer
1  
Or you could use readlink -f –  grawity Feb 7 '10 at 16:27
    
Thanks for the tip! –  mdpc Feb 8 '10 at 4:48
    
BTW- readlink is not present on solaris systems –  mdpc Feb 8 '10 at 18:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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