]>
git.rmz.io Git - dotfiles.git/blob - bin/old/rename
01bb2c924a5724ea2b6804886c1a54329473fefa
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 # This script is free software; you can redistribute it and/or modify it
7 # under the same terms as Perl itself.
9 # Larry(?)'s RCS header:
10 # RCSfile: rename,v Revision: 4.1 Date: 92/08/07 17:20:30
12 # $RCSfile: rename,v $$Revision: 1.5 $$Date: 1998/12/18 16:16:31 $
15 # Revision 1.5 1998/12/18 16:16:31 rmb1
16 # moved to perl/source
17 # changed man documentation to POD
19 # Revision 1.4 1997/02/27 17:19:26 rmb1
20 # corrected usage string
22 # Revision 1.3 1997/02/27 16:39:07 rmb1
25 # Revision 1.2 1997/02/27 16:15:40 rmb1
26 # *** empty log message ***
28 # Revision 1.1 1997/02/27 15:48:51 rmb1
35 Getopt
::Long
::Configure
('bundling');
37 my ($verbose, $no_act, $force, $op);
39 die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n"
41 'v|verbose' => \
$verbose,
42 'n|no-act' => \
$no_act,
46 $verbose++ if $no_act;
49 print "reading filenames from STDIN\n" if $verbose;
58 next if $was eq $_; # ignore quietly
59 if (-e
$_ and !$force)
61 warn "$was not renamed: $_ already exists\n";
63 elsif ($no_act or rename $was, $_)
65 print "$was renamed as $_\n" if $verbose;
69 warn "Can't rename $was $_: $!\n";
77 rename - renames multiple files
81 B<rename> S<[ B<-v> ]> S<[ B<-n> ]> S<[ B<-f> ]> I<perlexpr> S<[ I<files> ]>
86 renames the filenames supplied according to the rule specified as the
89 argument is a Perl expression which is expected to modify the C<$_>
90 string in Perl for at least some of the filenames specified.
91 If a given filename is not modified by the expression, it will not be
93 If no filenames are given on the command line, filenames will be read
96 For example, to rename all files matching C<*.bak> to strip the extension,
99 rename 's/\.bak$//' *.bak
101 To translate uppercase names to lower, you'd use
103 rename 'y/A-Z/a-z/' *
109 =item B<-v>, B<--verbose>
111 Verbose: print names of files successfully renamed.
113 =item B<-n>, B<--no-act>
115 No Action: show what files would have been renamed.
117 =item B<-f>, B<--force>
119 Force: overwrite existing files.
125 No environment variables are used.
137 If you give an invalid Perl expression you'll get a syntax error.
141 The original C<rename> did not check for the existence of target filenames,
142 so had to be used with care. I hope I've fixed that (Robin Barker).