Operating System - HP-UX
1833780 Members
2560 Online
110063 Solutions
New Discussion

Listing files links point to

 
SOLVED
Go to solution
dictum9
Super Advisor

Listing files links point to


I want to do ls on a link and have it take it me to the actual file that the link points to.

I found out that /etc has a lot of links that jump from directory to directory, and I just want to see the file they all point to.
8 REPLIES 8
Geoff Wild
Honored Contributor
Solution

Re: Listing files links point to

How about with find?

find / -type l -print

Rgds...Geof
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
James R. Ferguson
Acclaimed Contributor

Re: Listing files links point to

Hi:

# perl -MFile::Find -MCwd=realpath -le 'find(sub{print $File::Find::name," -> ",realpath($_) if -l},@ARGV)' /path

Regards!

...JRF...
dictum9
Super Advisor

Re: Listing files links point to

find doesn't do what I want.
I need the file permissions of /sbin/fs_wrapper, not to find out that /etc/newfs is a link, I already know that fact.




: ll /etc/newfs
lrwxr-xr-t 1 root sys 11 Nov 17 2005 /etc/newfs -> /sbin/newfs
baja7:/etc#: ll /sbin/newfs
lrwxr-xr-x 1 bin bin 16 Dec 1 2005 /sbin/newfs -> /sbin/fs_wrapper
baja7:/etc#: ll /sbin/fs_wrapper
-r-xr-xr-x 1 bin bin 647260 May 4 2005 /sbin/fs_wrapper
dictum9
Super Advisor

Re: Listing files links point to

James R. Ferguson

This is very cool. Seems simple to add another command to ascertain octal permissions of the file in question.

James R. Ferguson
Acclaimed Contributor

Re: Listing files links point to

Hi:

OK, so you want the permissions of the file to which the link points. Use this:

# cat ./links.pl
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use Cwd qw(realpath);
find(
sub {
printf "%s -> %s [ %04o ]\n", $File::Find::name, realpath($_),
( stat( realpath($_) ) )[2] & 07777
if -l && -e;
},
@ARGV
);
1;

...run, passing the path to interrogate, like:

# ./links.pl /etc

Regards!

...JRF...
Geoff Wild
Honored Contributor

Re: Listing files links point to

James's looks good...

You could do something as simple as:

for link in `ll |grep ^l |awk -F\> '{print $2}'`
do
ll $link
done

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Dennis Handly
Acclaimed Contributor

Re: Listing files links point to

If you want to see the info on what the symlink points to, you can just use "ll -L".
But it still has the link name.

You can also see this info by adding a trailing "/":
$ ll /etc/wall
lr-xr-sr-t 1 rootsys 14 Nov 28 2006 /etc/wall@ -> /usr/sbin/wall
$ ll /etc/wall/
-r-xr-sr-x 1 bin tty 16384 Mar 24 2003 /etc/wall/*
$ ll -L /etc/wall
-r-xr-sr-x 1 bin tty 16384 Mar 24 2003 /etc/wall*
dictum9
Super Advisor

Re: Listing files links point to

Thanks.