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