FILE-RENAME(1)
π FILE-RENAME(1) π
okay bestie, this is rename from the User Contributed Perl Documentation, and it is genuinely one of the most useful little gremlins in your toolbox. no cap. π
π NAME π
rename β renames multiple files. slay.
β¨ SYNOPSIS β¨
rename [ -h|-m|-V ] [ -v ] [ -0 ] [ -n ] [ -f ] [ -d ] [ -u [enc]]
[ -e|-E perlexpr]*|perlexpr [ files ]
π¦ DESCRIPTION π¦
rename renames the filenames you give it according to the rule specified as the first argument. the perlexpr argument is a Perl expression thatβs expected to modify the $_ string in Perl for at least some of the filenames you specify. if a given filename is not modified by the expression, it will not be renamed. periodt.
if no filenames are given on the command line, filenames will be read via standard input. yes bestie, stdin is eating. π
πΈ Examples (Larry Wall, 1992) πΈ
for example, to rename all files matching *.bak to 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/' ./*
Examples rewritten to avoid globs which could inject options. iykyk β safety is sexy.
π More examples (2020) π
you can also use rename to move files between directories, possibly at the same time as making other changes (but see --filename):
rename 'y/A-Z/a-z/;s/^/my_new_dir\//' ./*.*
you can also write the statements separately (see -e/-E):
rename -E 'y/A-Z/a-z/' -E 's/^/my_new_dir\//' -- *.*
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: print names of files successfully renamed. so you can see the glow-up happen.-0,--nullβ use\0as record separator when reading from STDIN. null-separated vibes.-n,--nonoβ No action: print names of files to be renamed, but donβt rename. itβs giving preview mode.-f,--forceβ Over write: allow existing files to be over-written. highkey chaotic if youβre not paying attention.--path,--fullpathβ rename the full path, including any directory component. this is the DEFAULT. main character behavior.-d,--filename,--nopath,--nofullpathβ do not rename the directory: only rename the filename component of the path. filename-only era.-h,--helpβ Help: printSYNOPSISandOPTIONS. emergency bestie button.-m,--manβ Manual: print the manual page. the lore.-V,--versionβ Version: show version number. receipts.-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 omitted, the next argument should be an option starting with'-', for instance-e. π§-eβ Expression: code to act on files name. may be repeated to build up code (likeperl -e). if no-e, the first argument is used as code.-Eβ Statement: code to act on files name, as-ebut terminated by';'. fancy punctuation behavior.
π ENVIRONMENT π
no environment variables are used. literally none. iconic minimalism.
π§ AUTHOR π§
Larry Wall. we stan.
π₯ SEE ALSO π₯
π DIAGNOSTICS π
if you give an invalid Perl expression youβll get a syntax error. not me making Perl mad again π
π BUGS π
β οΈ the original rename did not check for the existence of target filenames, so had to be used with care. fr fr, be careful out there.
mwah π β this cute little page is from perl v5.42.0, dated 2024-03-08. go rename something iconic, bestie π«Ά
π¦ 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