Links in Linux

How can i know if a file in linux is a link and to where it is pointing to?Couldnt find it, sorry... Thanks.
[137 byte] By [JavaGL] at [2007-9-30 4:27:32]
# 1
I think you have to do sth like:File file = new File();if (! file.getCanonicalPathName().equals(file.getAbsolutePathName()) {// its a link!}
fjsfjsfjs at 2007-7-1 13:16:37 > top of Java-index,Archived Forums,Java Programming...
# 2

A good idea.

However with this method you can not tell whether there was a directory name in the path, which itself was a symbolic link.

$ file bubu huhu

bubu: directory

huhu: symbolic link to bubu

$ ls -l bubu/birka huhu/birka

-rw-r--r--1 ijbalazs users4169 2004-03-26 14:25 bubu/birka

-rw-r--r--1 ijbalazs users4169 2004-03-26 14:25 huhu/birka

$ java ms huhu/birka

/home/ijbalazs/source/eBank/eBank8/bubu/birka

/home/ijbalazs/source/eBank/eBank8/huhu/birka

BIJ001 at 2007-7-1 13:16:37 > top of Java-index,Archived Forums,Java Programming...
# 3
I'll need that information too... any other suggestions?> A good idea. > > However with this method you can not tell whether> there was a directory name in the path, which itself> was a symbolic link.
JavaGL at 2007-7-1 13:16:37 > top of Java-index,Archived Forums,Java Programming...
# 4

If you want to know if the parent directory is a symbolic link then repeat the code from Reply 1, applied to the parent directory. Do this recursively until you arrive at a directory that is not a link (according to Reply 1 criteria). Then the directory or file in the previous step must have been a link.

My untested stab at an improved algorithm. BIJ001, go ahead and demolish that.

DrClap at 2007-7-1 13:16:37 > top of Java-index,Archived Forums,Java Programming...
# 5

> BIJ001, go ahead and demolish that.

I won't. On the given level of our knowledge, this imporeved version should obviously work. But the improvement seemed necessary and therefore I had taken the liberty to make my modest remark.

On the other hand, it would not be very difficult to write a native wrapper for "stat" in order to cope besides symlinks with other "monsters" dwelling in the file system as sockets, named pipes, devices...

BIJ001 at 2007-7-1 13:16:37 > top of Java-index,Archived Forums,Java Programming...