1PRENAME(1) User Contributed Perl Documentation PRENAME(1)
2
3
4
6 prename - renames multiple files
7
9 prename [-bfilnv] [-B prefix] [-S suffix] [-V method] [-Y prefix] [-z
10 suffix] [--backup] [--basename-prefix=prefix] [--dry-run] [--force]
11 [--help] [--no-stdin] [--interactive] [--just-print] [--link-only]
12 [--prefix=prefix] [--suffix=suffix] [--verbose]
13 [--version-control=method] [--version] perlexpr [files]...
14
16 prename renames the filenames supplied according to the rule specified
17 as the first argument. The argument is a Perl expression which is
18 expected to modify the $_ string for at least some of the filenames
19 specified. If a given filename is not modified by the expression, it
20 will not be renamed. If no filenames are given on the command line,
21 filenames will be read via standard input.
22
23 If a destination file is unwritable, the standard input is a tty, and
24 the -f or --force option is not given, mv prompts the user for whether
25 to overwrite the file. If the response does not begin with `y' or `Y',
26 the file is skipped.
27
29 -b, --backup
30 Make backup files. That is, when about to overwrite a file, rename
31 the original instead of removing it. See the -V or
32 --version-control option fo details about how backup file names are
33 determined.
34
35 -B prefix, --prefix=prefix
36 Use the simple method to determine backup file names (see the -V
37 method or --version-control=method option), and prepend prefix to a
38 file name when generating its backup file name.
39
40 -f, --force
41 Remove existing destination files and never prompt the user.
42
43 -h, --help
44 Print a summary of options and exit.
45
46 -no-stdin
47 Disable reading of filenames from STDIN. Us it when your shell has
48 nullglob enabled to make sure prename doesn't wait for input.
49
50 -i, --interactive
51 Prompt whether to overwrite each destination file that already
52 exists. If the response does not begin with `y' or `Y', the file
53 is skipped.
54
55 -l, --link-only
56 Link files to the new names instead of renaming them. This will
57 keep the original files.
58
59 -n, --just-print, --dry-run
60 Do everything but the actual renaming, insted just print the name
61 of each file that would be renamed. When used together with
62 --verbose, also print names of backups (which may or may not be
63 correct depending on previous renaming).
64
65 -v, --verbose
66 Print the name of each file before renaming it.
67
68 -V method, --version-control=method
69 Use method to determine backup file names. The method can also be
70 given by the RENAME_VERSION_CONTROL (or if that's not set, the
71 VERSION_CONTROL) environment variable, which is overridden by this
72 option. This option does not affect wheter backup files are made;
73 it affects only the name of any backup files that are made.
74
75 The value of method is like the GNU Emacs `version-control'
76 variable; prename also recognize synonyms that are more
77 descriptive. The valid values are (unique abbreviations are
78 accepted):
79
80 existing or nil
81 Make numbered backups of files that already have them,
82 otherwise simple backups. This is the default.
83
84 numbered or t
85 Make numbered backups. The numbered backup file name for F is
86 F.~N~ where N is the version number.
87
88 simple or never
89 Make simple backups. The -B or --prefix, -Y or
90 --basename-prefix, and -z or --suffix options specify the
91 simple backup file name. If none of these options are given,
92 then a simple backup suffix is used, either the value of
93 SIMPLE_BACKUP_SUFFIX environment variable if set, or ~
94 otherwise.
95
96 --version
97 Print version information on standard output then exit
98 successfully.
99
100 -Y prefix, --basename-prefix=prefix
101 Use the simple method to determine backup file names (see the -V
102 method or --version-control=method option), and prefix prefix to
103 the basename of a file name when generating its backup file name.
104 For example, with -Y .del/ the simple backup file name for a/b/foo
105 is a/b/.del/foo.
106
107 -z suffix, -S suffix, --suffix=suffix
108 Use the simple method to determine backup file names (see the -V
109 method or --version-control=method option), and append suffix to a
110 file name when generating its backup file name.
111
113 To rename all files matching *.bak to strip the extension, you might
114 say
115
116 prename 's/\e.bak$//' *.bak
117
118 To translate uppercase names to lower, you'd use
119
120 prename 'y/A-Z/a-z/' *
121
122 More examples:
123
124 prename 's/\.flip$/.flop/' # rename *.flip to *.flop
125 prename s/flip/flop/ # rename *flip* to *flop*
126 prename 's/^s\.(.*)/$1.X/' # switch sccs filenames around
127 prename 's/$/.orig/ */*.[ch]' # add .orig to source files in */
128 prename 'y/A-Z/a-z/' # lowercase all filenames in .
129 prename 'y/A-Z/a-z/ if -B' # same, but just binaries!
130 or even
131 prename chop *~ # restore all ~ backup files
132
134 Two environment variables are used, SIMPLE_BACKUP_SUFFIX and
135 VERSION_CONTROL. See "OPTIONS".
136
138 mv(1) and perl(1)
139
141 If you give an invalid Perl expression you'll get a syntax error.
142
144 Peder Stray <pederst@cpan.org>, original script from Larry Wall.
145
146
147
148perl v5.34.0 2021-07-27 PRENAME(1)