๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ“ File Management August 7, 2026 0

Linux Command: rename

Bulk rename files using patterns

Terminal โ€” File Management
Command
$ rename 's/\.txt$/.md/' *.txt

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 FILES

Key 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/' *.txt

Replace spaces with underscores

rename 's/ /_/g' *.pdf

Add prefix to all files

rename 's/^/2026-/' *.log

Pro 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 โ†’

Share this tip