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