RENAME(1p)
π RENAME(1p) β like, the file-rename manual bestie
okay so before we even start: this is RENAME(1p) from the User Contributed Perl Documentation crew, and it's genuinely one of those tools that changes your whole life once you get it. no cap. let's go π¦
β¨ NAME β¨
file-rename β renames multiple files π
like. multiple. files. at once. iconic behaviour fr.
πΈ SYNOPSIS πΈ
file-rename [ -h|-m|-V ] [ -v ] [ -0 ] [ -n ] [ -f ] [ -d ] [ -u [enc]] [ -e|-E perlexpr]*|perlexpr [ files ]
π DESCRIPTION π
So file-rename takes the filenames you hand it and renames them according to the rule you pass as the first argument. That's the whole vibe.
The perlexpr argument is a Perl expression, and it's expected to mess with the $_ string in Perl for at least some of the filenames you specified. Important bit, bestie: if your expression doesn't modify a given filename, that file just does not get renamed. No drama, no error, it simply sits there unbothered. π
And if you don't give any filenames on the command line at all? Then filenames get read via standard input. yes queen, pipes work.
π Examples (Larry Wall, 1992) π
not me citing the actual Larry Wall, the man himself, from 1992. legend behaviour.
So like, say you wanna rename all files matching *.bak and strip that extension off β you'd say:
file-rename -- 's/\.bak$//' *.bak
And to translate uppercase names to lower, you'd use:
file-rename 'y/A-Z/a-z/' ./*
These examples were rewritten to avoid globs which could inject options. (we do not let the globs start drama, thank you)
π¦ More examples (2020) π¦
A glow-up era. You can also use rename to move files between directories, possibly while making other changes at the same time β but bestie, go read --filename first, k?
file-rename 'y/A-Z/a-z/;s/^/my_new_dir\//' ./*.*
You can also write the statements separately (see -e/-E):
file-rename -E 'y/A-Z/a-z/' -E 's/^/my_new_dir\//' -- *.*
And you can use the predefined variables $a, $b in the code! For instance, to create sequences of numbers:
rename -e '$a++;s/\w+/file_$a/' -- *.*
numbering files automatically?? it's giving organized. it's giving main character energy. π₯
π OPTIONS π
the moment you've all been waiting for. every single one. no skips. periodt.
-v,--verboseβ Verbose: print the names of files that got successfully renamed. lil victory lap. π-0,--nullβ Use\0as the record separator when reading from STDIN.-n,--nonoβ No action: print the names of the files that would be renamed, but don't actually rename them. a dry run, a rehearsal, a vibe check. π«Ά-f,--forceβ Over write: allow existing files to be over-written. yes, it really means over-writing, be careful with this one bestie.--path,--fullpathβ Rename the full path: including any directory component. DEFAULT β (this is the default, so it's already doing this unless you say otherwise)-d,--filename,--nopath,--nofullpathβ Do not rename the directory: only rename the filename component of the path. so like, just the last bit.-h,--helpβ Help: print the SYNOPSIS and OPTIONS.-m,--manβ Manual: print the manual page. (hi, that's me, you're reading me πΈ)-V,--versionβ Version: show the version number.-u,--unicode [encoding]β Treat filenames as perl (unicode) strings when running the user-supplied code.
Decode/encode filenames using encoding, if present.
encoding is optional: if it's omitted, the next argument should be an option starting with -, for instance -e.
-eβ Expression: code to act on the file's name.
May be repeated to build up code (like perl -e). If there's no -e, the first argument is used as the code.
-Eβ Statement: code to act on the file's name, as-ebut terminated by;.
π± ENVIRONMENT π±
No environment variables are used. literally none. she's self-sufficient. she doesn't need your environment. π
π€ AUTHOR π€
Larry Wall π«Ά
π SEE ALSO π
π¨ DIAGNOSTICS π¨
If you give an invalid Perl expression you'll get a syntax error. that's it, that's the diagnostic. Perl said "no β€οΈ" and moved on.
π BUGS π
The original rename did not check for the existence of target filenames, so it had to be used with care. π
fr fr, read that again. it did not check. use it carefully.
and that's the page bestie!! this was perl v5.36.0, dated 2024-01-01, served fresh from RENAME(1p) β go rename something cute, and remember: run it with -n first if you're scared. mwah πβ¨π
π¦ where this page comes from
- debian trixie: rename 2.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: rename 2.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: rename 2.02-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms