Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: checking link files



On 7/28/07, pol <linux_milano@xxxxxxxx> wrote:
>
> To tell real files from symbolic links, so as to separate the filename from
> the  path to be able to change to the actual file the link is pointing to,

On a linux system, at least, you can do something like this:
~>cd /tmp
/tmp>touch a
/tmp>ln -s a b
/tmp>ln -s b c
/tmp>ln -s c d
/tmp>readlink -f a
/tmp/a
/tmp>readlink -f b
/tmp/a
/tmp>readlink -f c
/tmp/a
/tmp>readlink -f d
/tmp/a

so, you should be able to just use
file=$(readlink -f "$file")
assuming you'd like to resolve links recursively, so that a link to a
link to a file resolves to the file and not the middle link.

~Matt



Messages sorted by: Reverse Date, Date, Thread, Author