How to find symlink target name in script
Hey,
I have a symlink ~/bin/foo/image.link that points to ~/photos/image.jpg I am looking for a command kind of like this: Quote:
Code:
$ ls -l ~/bin/foo/image.link Is there a command you know of/option to 'ls' ?? Or is 'sed'/'awk' something I should look into?? Thanks, |
file somefile | awk '{print $5}'
or ls -l somefile | awk '{print $11}' |
Perfect!
That's exactly what I needed. I suppose I could have read the 'awk' man page but at the time it seemed so daunting, at least now I understand the basics of it. Thank you! P.S. There you go Jeremy (and macemoneta) yet another satified Linux user, at least untill I come up with another Question! :) |
Well after a long time of not thinking about this I was poking around and found the readlink command:
Code:
$readlink --help Also it is contained in the coreutils package (Ubuntu) so most if not all distros will have it. |
One more reason to use readlink is that it can follow recursively
I know is an extremely old thread, but hey, some of these tips are still valid after years!!!
I just wanted to point out one advantage of using readlink instead of the awk solution is that readlink can follow links recursively as opposed to the awk solution. for example, I found this thread trying to find a way to get the real java command in my system (in a script), so I ended up doing this: Code:
readlink -f $(which java) Code:
which java -> /usr/bin/java |
All times are GMT -5. The time now is 11:52 PM. |