1: #!/bin/sh
2: # For people who eat megabytes like corn chips..
3: #
4: # Inspired by overflowing partitions and the pretty shell
5: # code in Tales from the Abyss: UNIX File Recovery (SysAdmin
6: # Mag) at http://www.samag.com/documents/s=1441/sam0111b/0111b.htm
7: # You can also do things in shell like:
8: # for i in `find . `; do file $i | grep ASCII ; done
9: # Or replace $1 with a directory and paste from "find" at prompt.
10: # No need to shy away from the command line! read man bash
11: # (or man tcsh) and get results fast.
12: #
13: echo "Recursive search for symbolic links. Usage: findlinks dirname";
14: find $1 | file -f - | grep link\ to | awk -F: '{print $2 "\t" $1}' | sort -b +1 | perl -e '
15: $sy = "symbolic link"; $sb = "broken symbol"; $sl = length($sy);
16: while (<>) {
17: $m=$_; $m =~ s/^\s+//;
18: $n = $m;
19: $n =~ s/^(.+)\t(.+)$/$2\t\($1\)/; #WAS $n =~ s/^(.+)\t(.+)$/$2/;
20: if (substr($m,0,$sl) eq $sy) {push @sys,$n;}
21: elsif (substr($m,0,$sl) eq $sb) {push @sbs,$n;}
22: else {push @oth,$n;} #for debug
23: }
24: print "\n** Symbolic Links:\n", @sys, "\n** Broken Symbolic Links:\n", @sbs;
25: print "\nOthers:\n", @oth unless $#oth<0;
26: '
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unix Administration: Finding symbolic links with perl and *nix
by frag (Hermit) on Nov 14, 2001 at 06:26 UTC | |
by mattr (Curate) on Nov 15, 2001 at 12:31 UTC |