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.
2 Answers
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.)
-
yeah, that doesn't help much, the symlinks go forwards and backwards and there are often many ways to get to the same place.– StuFeb 5, 2010 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. Feb 5, 2010 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. Feb 5, 2010 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.– StuFeb 5, 2010 at 20:51
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);
}
-
1
-