tags:

views:

70

answers:

4

How can i get information via php or bash to what file referencing a symlink in linux?

A: 

If SYMPATH is a symlink to REALPATH, then

readlink SYMPATH

returns REALPATH

unutbu
+1  A: 

Use the readlink function or the readlink command.

joshperry
+1  A: 

In php you can use the realpath function.

Jason Jenkins
+4  A: 

Example from SplFileInfo::getLinkTarget

$info = new SplFileInfo('/Users/bbieber/workspace');
if ($info->isLink()) {
    var_dump($info->getLinkTarget());
    // gives string(19) "Documents/workspace"
    var_dump($info->getRealPath());   
    // gives string(34) "/Users/bbieber/Documents/workspace"
}
Gordon
And if i habe hardlink?
Jeje
`SplFileInfo::isLink`/`getLinkTarget` are only used for soft links. For hard links, they just appear as a regular file/directory: `isLink` will return `false`.
salathe
ok, i was wrong, i have hardlink, and none of this answers not working
Jeje