UNSAFE-RENAME(1)
π NAME π
rename β renames multiple files (and bestie, it eats, ok?)
β¨ SYNOPSIS β¨
rename [ -h|-m|-V ] [ -v ] [ -0 ] [ -n ] [ -f ] [ -d ] [ -u [enc]]
[ -e|-E perlexpr]*|perlexpr [ files ]
π¦ DESCRIPTION π¦
Okay so here's the vibe: rename takes the rule you hand it as the first argument and renames the filenames you gave it according to that rule. The perlexpr argument is a Perl expression, and it's expected to modify the $_ string in Perl for at least some of the filenames you passed in. π
And like β if a filename doesn't get modified by the expression? It just doesn't get renamed. No change, no rename, no drama. π
Also! If you give it no filenames on the command line, it reads filenames via standard input. Cute, right? π«Ά
πΈ Examples (Larry Wall, 1992) πΈ
So say you wanna rename every file matching *.bak and strip the extension off β iconic move, you'd say:
rename -- 's/\.bak$//' *.bak
And to translate uppercase names to lower (my toxic trait is loving this one), you'd use:
rename 'y/A-Z/a-z/' ./*
β οΈ Bestie, heads up: these examples got rewritten to avoid globs which could inject options. No cap. π
β More examples (2020) β
You can also use rename to move files between directories β possibly at the same time as making other changes (but lowkey see --filename):
rename 'y/A-Z/a-z/;s/^/my_new_dir\//' ./*.*
You can also write the statements separately (see -e/-E), which is giving main character energy:
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/' -- *.*
π₯ OPTIONS π₯
-v,--verboseβ Verbose mode: it prints the names of files successfully renamed. So you can see the slay. π-0,--nullβ Use\0as the record separator when reading from STDIN. Null-separated, no cap.-n,--nonoβ No action: prints the names of files that would be renamed, but doesn't actually rename them. It's a preview, a vibe check, a dress rehearsal. π-f,--forceβ Over write (yes that's how it's spelled, leave it): allow existing files to be over-written. Careful, bestie. π--path,--fullpathβ Rename full path: including any directory component. This one is the DEFAULT. β-d,--filename,--nopath,--nofullpathβ Do not rename the directory: only rename the filename component of the path. π-h,--helpβ Help: prints SYNOPSIS and OPTIONS. Your emergency contact.-m,--manβ Manual: prints the manual page. Hiii you're here π-V,--versionβ Version: shows 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 you omit it, the next argument should be an option starting with
-, for instance-e. iykyk.
-eβ Expression: code to act on files name.- May be repeated to build up code (like
perl -e). If no-e, the first argument is used as code. π§
- May be repeated to build up code (like
-Eβ Statement: code to act on files name, as-ebut terminated by';'. Periodt. π
π ENVIRONMENT π
No environment variables are used. Literally none. Zero. Clean slate, immaculate vibes. β¨
π AUTHOR π
Larry Wall π
π SEE ALSO π
π DIAGNOSTICS π
If you give it an invalid Perl expression you'll get a syntax error. That's it, that's the whole warning. π
π BUGS π
The original rename did not check for the existence of target filenames, so it had to be used with care. Fr fr, be careful out there bestie. π«Ά
Signing off: this adorable little page is from perl v5.42.0, dated 2024-03-08, and it lives in the UNSAFE-RENAME(1) section of the manual. Mwah! πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-File-Rename 2.20.0-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms