Is it possible to get the abolute path of the link that it is pointing to? Is there any simple system command?
I need for all of the following OS HP-UX 11i, 1123u, 1123i AIX 5.2 and 5.3 Suse Linux 10 Solaris 10
Is it possible to get the abolute path of the link that it is pointing to? Is there any simple system command?
I need for all of the following OS HP-UX 11i, 1123u, 1123i AIX 5.2 and 5.3 Suse Linux 10 Solaris 10
If you are looking for a system call, you want readlink(2)
. This is standardized, and so should be available on all POSIX compliant systems.
Here's an example of its usage, taken from the link given earlier:
#include <unistd.h>
char buf[1024];
ssizet_t len;
if ((len = readlink("/modules/pass1", buf, sizeof(buf)-1)) != -1)
buf[len] = '\0';
If you're looking for a command line utility, it doesn't look like there is one standardized, but GNU (Linux) and BSD both have readlink(1)
.
You didn't specify a language, so I assume you want a command that can be run in whatever shell you are using. The ls
command has the -l
(that is an ell) option which prints out a lot of information about the file. The last bit of information is the full path, so you should be able to say
ls -l file | awk '{print $NF}'
on any SUS2 compliant machine (which should be all of the commercial UNIXes). This will have a problem if the file or the any of the directories leading up to the file have spaces though.