Commit | Line | Data |
---|---|---|
9f68db38 | 1 | #!/usr/bin/perl |
00bf170e LW |
2 | 'di'; |
3 | 'ig00'; | |
4 | # | |
79072805 | 5 | # $RCSfile: relink,v $$Revision: 4.1 $$Date: 92/08/07 17:20:29 $ |
00bf170e LW |
6 | # |
7 | # $Log: relink,v $ | |
9f68db38 LW |
8 | |
9 | ($op = shift) || die "Usage: relink perlexpr [filenames]\n"; | |
10 | if (!@ARGV) { | |
00bf170e LW |
11 | @ARGV = <STDIN>; |
12 | chop(@ARGV); | |
9f68db38 LW |
13 | } |
14 | for (@ARGV) { | |
15 | next unless -l; # symbolic link? | |
16 | $name = $_; | |
17 | $_ = readlink($_); | |
18 | $was = $_; | |
19 | eval $op; | |
20 | die $@ if $@; | |
21 | if ($was ne $_) { | |
22 | unlink($name); | |
23 | symlink($_, $name); | |
24 | } | |
25 | } | |
00bf170e LW |
26 | ############################################################################## |
27 | ||
28 | # These next few lines are legal in both Perl and nroff. | |
29 | ||
30 | .00; # finish .ig | |
31 | ||
32 | 'di \" finish diversion--previous line must be blank | |
33 | .nr nl 0-1 \" fake up transition to first page again | |
34 | .nr % 0 \" start at page 1 | |
35 | ';<<'.ex'; #__END__ ############# From here on it's a standard manual page ############ | |
36 | .TH RELINK 1 "July 30, 1990" | |
37 | .AT 3 | |
38 | .SH LINK | |
39 | relink \- relinks multiple symbolic links | |
40 | .SH SYNOPSIS | |
41 | .B relink perlexpr [symlinknames] | |
42 | .SH DESCRIPTION | |
43 | .I Relink | |
44 | relinks the symbolic links given according to the rule specified as the | |
45 | first argument. | |
46 | The argument is a Perl expression which is expected to modify the $_ | |
47 | string in Perl for at least some of the names specified. | |
48 | For each symbolic link named on the command line, the Perl expression | |
49 | will be executed on the contents of the symbolic link with that name. | |
50 | If a given symbolic link's contents is not modified by the expression, | |
51 | it will not be changed. | |
52 | If a name given on the command line is not a symbolic link, it will be ignored. | |
53 | If no names are given on the command line, names will be read | |
54 | via standard input. | |
55 | .PP | |
56 | For example, to relink all symbolic links in the current directory | |
57 | pointing to somewhere in X11R3 so that they point to X11R4, you might say | |
58 | .nf | |
59 | ||
60 | relink 's/X11R3/X11R4/' * | |
61 | ||
62 | .fi | |
63 | To change all occurences of links in the system from /usr/spool to /var/spool, | |
64 | you'd say | |
65 | .nf | |
66 | ||
67 | find / -type l -print | relink 's#/usr/spool#/var/spool#' | |
68 | ||
69 | .fi | |
70 | .SH ENVIRONMENT | |
71 | No environment variables are used. | |
72 | .SH FILES | |
73 | .SH AUTHOR | |
74 | Larry Wall | |
75 | .SH "SEE ALSO" | |
76 | ln(1) | |
77 | .br | |
78 | perl(1) | |
79 | .SH DIAGNOSTICS | |
80 | If you give an invalid Perl expression you'll get a syntax error. | |
81 | .SH BUGS | |
82 | .ex |