FILE-RENAME(1)

πŸ“¦ version 2.20.0, in opensuse-leap 16.0

πŸ’… 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 \0 as 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: print SYNOPSIS and OPTIONS. 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 (like perl -e). if no -e, the first argument is used as code.
  • -E β€” Statement: code to act on files name, as -e but 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