in reply to Unix Administration: Finding symbolic links with perl and *nix

Well, TMTOWTDI, but I can't say that this will keep me from shying away from /.{0,3}sh/ scripts! Here's one Perl way to do it, courtesy of the Cookbook:
#!/usr/bin/perl -w use File::Find; find(\&wanted, shift || '.'); sub wanted { -l and not -e and print "bogus link: $File::Find::name\n"; }

-- Frag.
--
"Just remember what ol' Jack Burton does when the earth quakes, the poison arrows fall from the sky, and the pillars of Heaven shake. Yeah, Jack Burton just looks that big old storm right in the eye and says, "Give me your best shot. I can take it."

  • Comment on Re: Unix Administration: Finding symbolic links with perl and *nix
  • Download Code

Replies are listed 'Best First'.
Re: Re: Unix Administration: Finding symbolic links with perl and *nix
by mattr (Curate) on Nov 15, 2001 at 12:31 UTC
    Yep, you're right. Perl *does* rule.

    My motivation really came about when wrestling with a mixture of different ticks from a shell for loop and an awk command in that article.. this didn't work:

    # for i in 'file * | grep "ASCII C program text" | \ awk -F: '{print $1}'`; do mv $i $i.c; done
    The different ticks are tricky. You can try it by erasing "C program text" and changing mv to echo. Hmm, still not sure if that should work or not.

    Anyway, now instead of always relying on perl -pi (which also rules, let it be said) I feel personally a little more comfortable with piped operations on lists of files on the command line. Though I find that some shell tools pad output to both left and right justify at the same time.. this is a bad thing and Perl is still what I use for gardening.