BSD 4_4_Lite2 development
[unix-history] / usr / src / contrib / perl-4.036 / eg / rename
CommitLineData
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";
16if (!@ARGV) {
17 @ARGV = <STDIN>;
18 chop(@ARGV);
19}
20for (@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
39rename \- renames multiple files
40.SH SYNOPSIS
41.B rename perlexpr [files]
42.SH DESCRIPTION
43.I Rename
44renames the filenames supplied according to the rule specified as the
45first argument.
46The argument is a Perl expression which is expected to modify the $_
47string in Perl for at least some of the filenames specified.
48If a given filename is not modified by the expression, it will not be
49renamed.
50If no filenames are given on the command line, filenames will be read
51via standard input.
52.PP
53For example, to rename all files matching *.bak to strip the extension,
54you might say
55.nf
56
57 rename 's/\e.bak$//' *.bak
58
59.fi
60To translate uppercase names to lower, you'd use
61.nf
62
63 rename 'y/A-Z/a-z/' *
64
65.fi
66.SH ENVIRONMENT
67No environment variables are used.
68.SH FILES
69.SH AUTHOR
70Larry Wall
71.SH "SEE ALSO"
72mv(1)
73.br
74perl(1)
75.SH DIAGNOSTICS
76If you give an invalid Perl expression you'll get a syntax error.
77.SH BUGS
78.I Rename
79does not check for the existence of target filenames, so use with care.
80.ex