Batch rename files with the rename command
Rename dozens of files in one shot — swap extensions, replace spaces, add prefixes — without writing a loop.
01Command
$ rename 's/\.jpeg$/.jpg/' *.jpeg && rename 's/ /_/g' *.mp302What 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
04Undo
$ rename 's/\.jpg$/.jpeg/' *.jpg05Sources
- rename - renames multiple filesEvidence: 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
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
Show total, used, and available space plus usage percentage for every mounted filesystem in human-readable units.