Commit | Line | Data |
---|---|---|
ca2dddd6 C |
1 | #!/usr/bin/perl |
2 | 'di'; | |
3 | 'ig00'; | |
4 | # | |
5 | # $Header: rename,v 4.0 91/03/20 01:11:53 lwall Locked $ | |
6 | # | |
7 | # $Log: rename,v $ | |
8 | # Revision 4.0 91/03/20 01:11:53 lwall | |
9 | # 4.0 baseline. | |
10 | # | |
11 | # Revision 3.0.1.2 90/08/09 03:17:57 lwall | |
12 | # patch19: added man page for relink and rename | |
13 | # | |
14 | ||
15 | ($op = shift) || die "Usage: rename perlexpr [filenames]\n"; | |
16 | if (!@ARGV) { | |
17 | @ARGV = <STDIN>; | |
18 | chop(@ARGV); | |
19 | } | |
20 | for (@ARGV) { | |
21 | $was = $_; | |
22 | eval $op; | |
23 | die $@ if $@; | |
24 | rename($was,$_) unless $was eq $_; | |
25 | } | |
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 RENAME 1 "July 30, 1990" | |
37 | .AT 3 | |
38 | .SH NAME | |
39 | rename \- renames multiple files | |
40 | .SH SYNOPSIS | |
41 | .B rename perlexpr [files] | |
42 | .SH DESCRIPTION | |
43 | .I Rename | |
44 | renames the filenames supplied 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 filenames specified. | |
48 | If a given filename is not modified by the expression, it will not be | |
49 | renamed. | |
50 | If no filenames are given on the command line, filenames will be read | |
51 | via standard input. | |
52 | .PP | |
53 | For example, to rename all files matching *.bak to strip the extension, | |
54 | you might say | |
55 | .nf | |
56 | ||
57 | rename 's/\e.bak$//' *.bak | |
58 | ||
59 | .fi | |
60 | To translate uppercase names to lower, you'd use | |
61 | .nf | |
62 | ||
63 | rename 'y/A-Z/a-z/' * | |
64 | ||
65 | .fi | |
66 | .SH ENVIRONMENT | |
67 | No environment variables are used. | |
68 | .SH FILES | |
69 | .SH AUTHOR | |
70 | Larry Wall | |
71 | .SH "SEE ALSO" | |
72 | mv(1) | |
73 | .br | |
74 | perl(1) | |
75 | .SH DIAGNOSTICS | |
76 | If you give an invalid Perl expression you'll get a syntax error. | |
77 | .SH BUGS | |
78 | .I Rename | |
79 | does not check for the existence of target filenames, so use with care. | |
80 | .ex |