file-rename
Rename files
TLDR
View documentation for the original command
SYNOPSIS
rename [options] expression replacement file...
PARAMETERS
-v, --verbose
Print names of files successfully renamed
-n, --no-act
Dry run: show what would be renamed without changes
-f, --force
Overwrite existing files
-a
Rename all files, even if target exists (force)
-0
Split filenames on null bytes (for xargs)
-p
Rename pathnames (directories too)
-e code
Execute Perl code for renaming
--help
Display usage summary
--version
Show version info
DESCRIPTION
The rename command, often called Perl rename or prename, is a powerful utility for renaming multiple files at once using Perl regular expressions. It applies a substitution pattern (expression replacement) to the filenames matching the expression.
Unlike simple tools like mv, it supports complex regex patterns, making it ideal for bulk operations like changing extensions, numbering sequences, or standardizing names. For example, rename 's/.txt$/.bak/' *.txt converts all .txt files to .bak.
It processes files in place, scanning arguments for matches. Options control verbosity, simulation, and overwriting. Note: distributions may have variants; Ubuntu/Debian use the Perl version from the rename package, while some use util-linux rename for simpler from-to renaming. Always verify with man rename.
Key strength: regex power from Perl. Use -n for dry runs to preview changes.
CAVEATS
Regex errors halt processing; test with -n. Not recursive by default. Conflicting variants in some distros (Perl vs. util-linux). Escaping special chars needed in expressions.
EXAMPLE
rename 's/foo/bar/' foo*.txt
Replaces 'foo' with 'bar' in matching files.
COMPLEX EXAMPLE
rename 's/^(.*)-\d+\.jpg$/sprintf("%s.jpg",$1)/e' *.jpg
Removes trailing numbers from JPEGs.
HISTORY
Originally written by Larry Wall in 1988 as part of Perl tools. Evolved into standalone utility; modern versions maintained separately (e.g., Debian's by Antonio Radici). util-linux variant added simpler syntax in 2011.


