UNSAFE-RENAME(1)

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

πŸ’… 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 \0 as 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. 🧚
  • -E β€” Statement: code to act on files name, as -e but terminated by ';'. Periodt. πŸ’…

🌈 ENVIRONMENT 🌈

No environment variables are used. Literally none. Zero. Clean slate, immaculate vibes. ✨


πŸ’œ AUTHOR πŸ’œ

Larry Wall πŸ‘‘


πŸŽ€ SEE ALSO πŸŽ€

mv(1), perl(1)


πŸ™ˆ 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