Linux Command: rename
Bulk rename files using patterns
The rename command renames multiple files at once using pattern matching โ either Perl regular expressions (Perl rename) or simple string substitution (util-linux rename). It is far more powerful than manual mv commands when you need to rename dozens or hundreds of files following a pattern. There are two common versions of rename on Linux: the Perl-based rename (also called prename or perl-rename, default on Debian/Ubuntu) which supports full Perl regular expressions, and the util-linux rename (default on RHEL/Fedora) which supports simple string substitution. This guide covers both. Common use cases include changing file extensions, adding prefixes or suffixes, converting case, removing spaces, numbering files sequentially, and batch-renaming photos, logs, or data files. Combined with find, rename can process files recursively across directory trees.
Syntax
rename [OPTIONS] 's/PATTERN/REPLACEMENT/' FILES
rename [OPTIONS] PATTERN REPLACEMENT FILESKey Options
's/old/new/'โ Perl rename: substitute old with new using regex-nโ Dry run - show what would be renamed without doing it-vโ Verbose - show each rename operation-fโ Force - overwrite existing files's/old/new/g'โ Global - replace all occurrences (not just first)'s/PATTERN/\L$&/'โ Convert matching text to lowercase
Examples
Change file extension
rename 's/\.txt$/.md/' *.txtReplace spaces with underscores
rename 's/ /_/g' *.pdfAdd prefix to all files
rename 's/^/2026-/' *.logPro Tips
- Test with rename -n (dry run) before executing. Complex regex patterns can produce unexpected results. Verify the preview before running without -n.
- Debian/Ubuntu has Perl rename (regex). RHEL/Fedora has util-linux rename (string substitution). Install Perl version with: apt install rename or dnf install prename.
- Rename files in subdirectories: find . -name '*.txt' -exec rename 's/\.txt$/.md/' {} +
Learn more: Full rename reference โ
Related Resources