Batch rename files with the rename command

Rename dozens of files in one shot — swap extensions, replace spaces, add prefixes — without writing a loop.

LinuxrenamebatchFilesMedium risk
Run rename with a Perl substitution pattern and a file glob to rename every matching file at once.

01Command

Command
$ rename 's/\.jpeg$/.jpg/' *.jpeg && rename 's/ /_/g' *.mp3

02What it does

The rename utility applies a Perl regular expression to each filename: the s/old/new/ part says what to replace and the glob like *.jpeg picks which files. Unlike a shell for-loop, it handles all matches in a single command and fails cleanly on naming conflicts. Use -n to preview changes without touching anything.

03Risk

RiskMedium risk
Requirementsrename utility (Debian/Ubuntu package `rename`; on Fedora install `perl-rename` and run `perl-rename`)
!Warning: Patterns are regular expressions — a stray dot or star can rename files in unexpected ways. Always dry-run with rename -n 's/…/…/' files first, and keep a copy of important folders.

04Undo

Undo
$ rename 's/\.jpg$/.jpeg/' *.jpg

05Sources

  • rename - renames multiple files
    manpages.debian.org · community · 2026-09-17
    Evidence: rename applies a Perl regular expression substitution to each filename given, renaming all matching files in one run.

Last verified: 2026-09-18 · Category: Files & Folders

06Related solutions