Quick take: The rename command renames many files at once using patterns. The Perl version uses regex: rename 's/\.jpeg$/.jpg/' *.jpeg changes every .jpeg to .jpg. Add -n to preview before committing.
Introduction
While mv renames one file at a time, the rename command renames many at once using patterns — perfect for changing extensions, fixing naming schemes, or replacing text across a batch of files. Note that two versions exist: the powerful Perl-based rename common on Debian/Ubuntu, and a simpler util-linux version elsewhere.
Syntax
The basic syntax of the rename command is:
rename [OPTIONS] 's/OLD/NEW/' FILES # Perl versionCommon Options and Parameters
The most useful options and parameters for the rename command:
| Option | Description |
|---|---|
| -n | Dry run — show what would be renamed without doing it. |
| -v | Verbose — print each rename as it happens. |
| -f | Force — overwrite existing files. |
| 's/old/new/' | Perl substitution applied to each filename. |
| 'y/A-Z/a-z/' | Transliterate (e.g. uppercase to lowercase). |
Practical Examples
Real rename commands you can run today:
# Preview changing .jpeg to .jpg
rename -n 's/\.jpeg$/.jpg/' *.jpeg
# Actually change the extension
rename 's/\.jpeg$/.jpg/' *.jpeg
# Replace spaces with underscores
rename 's/ /_/g' *
# Lowercase all filenames
rename 'y/A-Z/a-z/' *
# Add a prefix to files
rename 's/^/2026_/' *.txtTips and Best Practices
- Always run with
-nfirst to preview the renames — pattern mistakes can rename far more than you intended. - Check which rename you have:
rename --version. The Perl version takes a regex; the util-linux version takesrename from to files. - For one-off renames, plain
mv old newis simpler; reach for rename when changing many files by pattern.
Final Thoughts
rename brings pattern power to file renaming, turning a tedious loop into a single command — changing extensions, fixing spaces, or re-casing names en masse. Always preview with -n, confirm which version you have, and keep mv for single files. For complex cases, a for loop with basename remains a portable fallback.
FAQ: rename Command in Linux
How do I rename multiple files at once in Linux?+
Use the rename command with a pattern. On Debian/Ubuntu, rename 's/\.txt$/.md/' *.txt changes every .txt to .md. Always test with -n first to preview the changes.
How do I change file extensions in bulk?+
Use a substitution pattern: rename 's/\.jpeg$/.jpg/' *.jpeg. The regex matches the old extension at the end of the name and replaces it.
How do I preview renames before applying them?+
Add -n (dry run): rename -n 's/old/new/' * prints what would be renamed without changing anything, so you can confirm the pattern is correct.
Why does my rename command behave differently?+
There are two versions: the Perl-based rename (Debian/Ubuntu) takes a regex, while the util-linux version uses rename from to files. Run rename --version to see which you have.
How do I rename files without the rename command?+
Use a loop with mv and basename: for f in *.jpeg; do mv "$f" "$(basename "$f" .jpeg).jpg"; done. This is portable across systems that lack rename.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support