#!/usr/bin/perl ########################################### # symlinkdir -- Resolve symlinks # Documentation: 'perldoc symlinkdir' ########################################### use Getopt::Std; use Pod::Usage; use File::Basename; our $VERSION = "1.00"; our $CVSVERSION = '$Revision: 1.3 $'; my($link) = @ARGV; pod2usage("No link specified") unless $link; pod2usage("$link not a symbolic link") unless -l $link; while(-l $link) { $link = readlink($link); } $link = dirname($link) unless -d $link; print "$link\n"; __END__ =head1 NAME symlinkdir - Display the directory a symlink points to =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS symlinkdir =head1 DESCRIPTION This seemingly useless script saves considerable time if used during command-line-browsing through directories following symlinks. C displays the directory a symbolic link points to. If you're in C and there's a symbolic link C which points to C, you can quickly change to the directory the original C file is located in (C) by typing cds MyModule.pm given that your C or similar shell defined a function function cds () { cd `symlinkdir $1`; pwd; ls; } C resolves symbolic links recursively, so if you have a link C pointing to C pointing to C, it will properly display C when called on C. If the link points to a directory instead of a file, C will display this directory instead of going an additional level up. =head1 LEGALESE Copyright 2002 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Mike Schilli Em@perlmeister.comE