3 # This script was developed by Robin Barker (Robin.Barker@npl.co.uk),
4 # from Larry Wall's original script eg/rename from the perl source.
6 # Then further developed by A Hrubak and renamed to rename.td,
7 # because he was not aware of newer versions, like file-rename(1p) (alias prename).
9 # This script is free software; you can redistribute it and/or modify it
10 # under the same terms as Perl itself.
12 # Larry(?)'s RCS header:
13 # RCSfile: rename,v Revision: 4.1 Date: 92/08/07 17:20:30
15 # $RCSfile: rename,v $$Revision: 1.5 $$Date: 1998/12/18 16:16:31 $
18 # Revision 1.5 1998/12/18 16:16:31 rmb1
19 # moved to perl/source
20 # changed man documentation to POD
22 # Revision 1.4 1997/02/27 17:19:26 rmb1
23 # corrected usage string
25 # Revision 1.3 1997/02/27 16:39:07 rmb1
28 # Revision 1.2 1997/02/27 16:15:40 rmb1
29 # *** empty log message ***
31 # Revision 1.1 1997/02/27 15:48:51 rmb1
38 Getopt
::Long
::Configure
('bundling');
41 my ($no_act, $force, $op);
43 die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n"
45 'v|verbose+' => \
$verbose,
46 'n|no-act|dry-run|dryrun' => \
$no_act,
51 print STDERR
"reading filenames from STDIN\n" if $verbose;
61 return if $header_emitted;
62 print join "\t", "STATUS", "OLD", "NEW";
76 $status = "KEEP" if $verbose >= 2;
78 elsif (-e
$_ and !$force)
92 $status = "OK" if $verbose;
97 $status = "ERR $errno";
98 $highest_errno = $errno if $errno > $highest_errno;
106 print join "\t", $status, $was, $_;
117 rename.td - rename multiple files by a Perl expression
121 rename.td S<[ B<-v>[B<v>] ]> S<[ B<-n> ]> S<[ B<-f> ]> I<perlexpr> S<[ I<files> ]>
123 cat files.list | rename.td S<[ B<-v>[B<v>] ]> S<[ B<-n> ]> S<[ B<-f> ]> I<perlexpr>
127 B<rename.td> renames the files supplied according to the rule specified as the first argument.
128 The I<perlexpr> argument is a Perl expression which is expected to modify the C<$_>
129 string in Perl for at least some of the filenames specified.
130 If a given filename is not modified by the expression, it will not be renamed.
131 If no filenames are given on the command line, filenames will be read via standard input.
133 For example, to rename all files matching C<*.bak> to strip the extension,
136 rename.td 's/\.bak$//' *.bak
138 To translate uppercase names to lower, you'd use
140 rename.td 'y/A-Z/a-z/' *
146 =item B<-v>, B<--verbose>
148 Verbose: print names of files successfully renamed.
152 Verbose extra: print names of files of which name is not changed.
154 =item B<-n>, B<--dry-run>, B<--no-act>
156 No Action: show what files would have been renamed, or skipped.
158 =item B<-f>, B<--force>
160 Force: overwrite existing files.
166 Output Tab-delimited fields line-by-line.
167 First line is the headers.
168 Each subsequent line describes a file in this way:
172 =item 1st field - status
176 =item B<KEEP> - no change in file name, shown in B<-vv> mode
178 =item B<SKIP> - destination already exists, not in B<--force> mode
180 =item B<WOULD> - would be attempted to rename, in B<--dry-run> mode
182 =item B<OK> - successfully renamed
184 =item B<ERR I<nnn>> - error happened during rename, error code is I<nnn>
188 =item 2nd field - old file name
190 =item 3rd field - new file name
196 Zero when all rename succeeded, otherwise the highest error number of all the failed renames, if any.
197 See rename(2) for these error numbers.
201 No environment variables are used.
205 Larry Wall (author of the original)
211 mv(1), perl(1), rename(2), file-rename(1p) (prename(1)), rename.ul (rename(1)), renamemanual(1)
215 If you give an invalid Perl expression you'll get a syntax error.
219 The original C<rename> did not check for the existence of target filenames,
220 so had to be used with care. I hope I've fixed that (Robin Barker).