PRENAME(1)
π PRENAME π
ok so first things first, bestie: this is the prename man page from the User Contributed Perl Documentation section (section 1, obviously), and it's literally the glow-up your messy file names have been waiting for. buckle up π
β¨ NAME β¨
prename β renames a whole bunch of files at once using perl expressions. yes, plural. yes, at once. slay.
πΈ SYNOPSIS πΈ
prename [-bcfilnv] [-B prefix] [-S suffix] [-V method] [-Y prefix] [-z
suffix] [--backup] [--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 π¦
ok so here's the whole vibe: prename renames the filenames you hand it, following the rule you gave as the first argument. that rule is a Perl expression, and the entire expectation is that it modifies the $_ string for at least some of the filenames you passed in. that's it. that's the assignment.
important detail fr: if a given filename does not get modified by your expression, it does not get renamed. no changes, no chaos, it just sits there looking cute.
and if you don't give any filenames on the command line? then filenames get read in via standard input instead β unless you passed --no-stdin on the command line, in which case nope, not doing that.
now the spicy part π₯: if a destination file is unwritable, AND standard input is a tty, AND you did not give -f or --force, then prename will actually prompt you about whether to overwrite the file. if your response doesn't start with y or Y, the file gets skipped. no take-backs, no drama.
π OPTIONS π
-b,--backupβ make backup files, bestie. meaning: when it's about to overwrite a file, it renames the original instead of yeeting it. (check-V/--version-controlfor how the backup file names actually get figured out.)-B prefix,--prefix=prefixβ uses the simple method for determining backup file names (peep the-V method/--version-control=methodoption for that), and sticksprefixon the front of a file name when it generates that file's backup file name.-c,--copyβ copies files to the new names instead of renaming them. the original files stay put. icon behaviour, honestly π«Ά-f,--forceβ removes existing destination files and never prompts the user. aggressive. powerful. use with intent π-h,--helpβ prints a summary of the options and dips.--no-stdinβ turns off reading filenames from STDIN. use it when your shell hasnullglobenabled soprenamedoesn't just sit there waiting for input like ποΈπποΈ-i,--interactiveβ prompts you about whether to overwrite each destination file that already exists. if the response doesn't begin withyorY, the file is skipped. consent matters β¨-l,--link-onlyβ links files to the new names instead of renaming them. original files? kept. we love a non-destructive queen.-n,--just-print,--dry-runβ does everything except the actual renaming; instead it just prints the name of each file that would be renamed. and when you use it together with--verbose, it also prints names of backups β which may or may not be correct depending on previous renaming. (so like, cute preview, but read it with a little skepticism π)-v,--verboseβ prints the name of each file before renaming it. narration! we stan a transparent process.-V method,--version-control=methodβ usesmethodto determine backup file names.methodcan also be given by theRENAME_VERSION_CONTROLenvironment variable (or, if that one's not set, theVERSION_CONTROLenvironment variable) β and this option overrides those. huge clarification: this option does not affect whether backup files are made. it only affects the name of any backup files that are made.
the value of method is like the GNU Emacs version-control variable, and prename also recognizes synonyms that are more descriptive. the valid values are (unique abbreviations are accepted):
existingornilβ makes numbered backups of files that already have them, otherwise simple backups. this is the default.numberedortβ makes numbered backups. the numbered backup file name for F isF.~N~where N is the version number.simpleorneverβ makes simple backups. the-Bor--prefix,-Yor--basename-prefix, and-zor--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β prints version information on standard output, then exits successfully. bye bestie π-Y prefix,--basename-prefix=prefixβ uses the simple method for determining backup file names (again, see-V method/--version-control=method), and prefixesprefixto 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. see how that works? the basename got the prefix, the directory stayed iconic π-z suffix,-S suffix,--suffix=suffixβ uses the simple method for determining backup file names (yep,-V method/--version-control=methodagain), and appendssuffixto a file name when generating its backup file name.--shell-completion=shell,--shellcompletion=shellβ generates shell code for parameter completion for eitherbashorzsh. tab-completion stans rise π
π₯ EXAMPLES π₯
want to rename all files matching *.bak to strip the extension? you might say:
prename 's/\e.bak$//' *.bak
want to translate uppercase names to lower? you'd use:
prename 'y/A-Z/a-z/' *
more examples, because we're generous:
prename 's/\.flip$/.flop/' * # rename *.flip to *.flop
prename s/flip/flop/ * # rename *flip* to *flop*
prename 's/^s\.(.*)/$1.X/' * # switch sccs filenames around
prename 's/$/.orig/' */*.[ch] # add .orig to source files in */
prename 'y/A-Z/a-z/' * # lowercase all filenames in .
prename 'y/A-Z/a-z/ if -B' * # same, but just binaries!
or even:
prename chop *~ # restore all ~ backup files
π ENVIRONMENT π
two environment variables are in play: SIMPLE_BACKUP_SUFFIX and VERSION_CONTROL. see "OPTIONS" above for the whole story π
π§ SEE ALSO π§
mv(1) and perl(1). go give them a little visit, they're family.
β DIAGNOSTICS β
if you give an invalid Perl expression, you'll get a syntax error. that's the whole diagnostic. perl said what it said π
π AUTHOR π
Peder Stray <pederst@cpan.org> β and the original script is from Larry Wall. legends only.
πΈ BUGS πΈ
report any issues at <https://github.com/pstray/rename/issues>. (yes bestie, real link, go click it if something's cursed.)
ok that's the whole page π this was perl v5.32.1, dated 2023-06-22, served fresh from the PRENAME(1) corner of the User Contributed Perl Documentation. go forth and rename responsibly, mwah πβ¨
π¦ where this page comes from
- epel 9: prename 1.14-1.el9 Β· GPL+ or Artistic
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms