RENAME(1)
π RENAME(1) β the perl-powered renamer π
okay so first things first, bestie: this page lives in the User Contributed Perl Documentation section, and it's about rename β yes, the one that renames multiple files using perl expressions. genuinely iconic.
β¨ NAME β¨
rename β rename multiple files using perl expressions π¦
β¨ SYNOPSIS β¨
rename [-bcfgilnv] [-B prefix] [-C command] [-S suffix] [-V method] [-Y
prefix] [-z suffix] [--backup] [--command=command] [--copy]
[--basename-prefix=prefix] [--dry-run] [--force] [--help] [--no-stdin]
[--interactive] [--just-print] [--link-only] [--prefix=prefix]
[--suffix=suffix] [--verbose] [--version-control=method] [--version]
perlexpr [files]...
β¨ DESCRIPTION β¨
so rename renames the filenames you hand it, according to the rule you give as the first argument. that argument is a Perl expression, and the whole vibe is that it's expected to modify the $_ string for at least some of the filenames you listed. πͺ
lowkey important: if a filename doesn't get modified by your expression, it does not get renamed. no change, no rename, periodt.
and if you give no filenames on the command line, the filenames get read via standard input β unless you passed --no-stdin on the command line (more on that below π).
π«Ά also: if a destination file is unwritable, and standard input is a tty, and you didn't give-for--force, thenrenamewill prompt you about whether to overwrite the file. if your response doesn't begin withyorY, the file gets skipped. no cap.
π OPTIONS π
-b,--backupβ make backup files πΎ. meaning: when it's about to overwrite a file, rename the original instead of removing it. the deets on how backup file names get determined live in the-V/--version-controloption.-B prefix,--prefix=prefixβ use the simple method to determine backup file names (peep the-V method/--version-control=methodoption), and prependprefixto a file name when generating its backup file name.-c,--copyβ copy files to the new names instead of renaming them π«Ά. this keeps the original files. (yes, this is the "i want both" option, slay.)-C command,--cmd command,--command commandβ usecommandto process files instead of rename.commandcan contain two instances of{}β the first gets replaced with the original filename, the second with the new one. if there are no{}'s at all, the old and new filename get appended to the command. π₯-f,--forceβ remove existing destination files and never prompt the user. no questions, just vibes.-g,--gitβ shortcut for--command "git mv"π§-h,--helpβ print a summary of options and exit.--no-stdinβ disable reading of filenames from STDIN. use it when your shell hasnullglobenabled, so you can be surerenamedoesn't sit there waiting for input π (the page literally spells it "Us it" β we're not fixing that, we're just telling you what it means.)-i,--interactiveβ prompt whether to overwrite each destination file that already exists. if the response doesn't begin withyorY, the file is skipped. consent culture fr fr π-l,--link-onlyβ link files to the new names instead of renaming them. this keeps the original files. π-n,--just-print,--dry-runβ do everything but the actual renaming; instead, just print the name of each file that would be renamed. when used together with--verbose, it also prints names of backups (which may or may not be correct depending on previous renaming). π-v,--verboseβ print the name of each file before renaming it. main character energy.-V method,--version-control=methodβ usemethodto determine backup file names. the method can also be given by theRENAME_VERSION_CONTROLenvironment variable (or if that's not set, theVERSION_CONTROLenvironment variable), which this option overrides. heads up: this option does not affect whether backup files are made β it affects only the name of any backup files that are made. β
the value of method is like the GNU Emacs version-control variable; rename also recognizes synonyms that are more descriptive. the valid values are (unique abbreviations are accepted):
existingornilβ make numbered backups of files that already have them, otherwise simple backups. this is the default. πnumberedortβ make numbered backups. the numbered backup file name for F is F.~N~where N is the version number.simpleorneverβ make simple backups. the-B/--prefix,-Y/--basename-prefix, and-z/--suffixoptions specify the simple backup file name. if none of these options are given, then a simple backup suffix is used β either the value of theSIMPLE_BACKUP_SUFFIXenvironment variable if set, or~otherwise. πΈ
--versionβ print version information on standard output then exit successfully. π-Y prefix,--basename-prefix=prefixβ use the simple method to determine backup file names (again:-V method/--version-control=method), and prefixprefixto the basename of a file name when generating its backup file name. for example, with-Y .del/the simple backup file name fora/b/fooisa/b/.del/foo. π¦-z suffix,-S suffix,--suffix=suffixβ use the simple method to determine backup file names (yes,-V method/--version-control=methodagain), and appendsuffixto a file name when generating its backup file name.--shell-completion=shell,--shellcompletion=shellβ generate shell code for parameter completion, for eitherbashorzsh. β¨
π EXAMPLES π
to rename all files matching *.bak and strip the extension, you might say:
rename 's/\.bak$//' *.bak
to translate uppercase names to lower, you'd use:
rename 'y/A-Z/a-z/' *
more examples, because we love a demo:
rename 's/\.flip$/.flop/' * # rename *.flip to *.flop
rename s/flip/flop/ * # rename *flip* to *flop*
rename 's/^s\.(.*)/$1.X/' * # switch sccs filenames around
rename 's/$/.orig/' */*.[ch] # add .orig to source files in */
rename 'y/A-Z/a-z/' * # lowercase all filenames in .
rename 'y/A-Z/a-z/ if -B' * # same, but just binaries!
or even:
rename chop *~ # restore all ~ backup files
use --git when you're working within a GIT repo π§:
# rename _-separated filenames to camel-case, using git mv
rename --git 's/([a-z]+)_/\u\L$1/g' *.c
# or just renaming all the *.yml files to *.yaml
rename -g 's/\.yml$/.yaml/ *.yml
with the --command parameter you can make rename do other interesting stuff like:
# make thumbnails in PNG format of all JPEG file
rename 's/\.jpg/-thumb.png/' -C 'convert {} -resize 120x120 {}' *.jpg
π ENVIRONMENT π
two environment variables are used: SIMPLE_BACKUP_SUFFIX and VERSION_CONTROL. peep "OPTIONS" for the details π
π¦ SEE ALSO π¦
π DIAGNOSTICS π
if you give an invalid Perl expression you'll get a syntax error. (rude, but fair.)
π AUTHOR π
Peder Stray <pederst@cpan.org>, original script from Larry Wall. absolute legends, both of them π«Ά
π BUGS π
report any issues at <https://github.com/pstray/rename/issues>. bestie behavior honestly.
okay that's the whole page!! π this one's perl v5.42.0, dated 2026-02-02, and it's the RENAME(1) page from the User Contributed Perl Documentation β go forth and rename things slayfully β¨ππ
π¦ where this page comes from
- arch rolling: perl-rename 1.16.3-1 Β· GPL-1.0-or-later AND Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms