The rename command is a Perl-based utility in Linux used to rename single or multiple files quickly using pattern matching. It is especially useful when you need to modify filenames in bulk.
General Syntax
rename [ -v ] [ -n ] [ -f ] perlexpr [ files ] Options Explained
- -v — Verbose mode. Displays renamed files.
- -n — Test mode. Shows the expected result without making changes.
- perlexpr — A Perl expression used to define the rename rule.
Example Command
rename -n 's/\.htm$/\.html/' *.htm The -n option performs a dry run and displays how files will be renamed without actually modifying them.
If the output looks correct, run the final command:
rename -v 's/\.htm$/\.html/' *.htm This command renames all files ending with .htm to .html.
Command Breakdown
- s → Substitute operation.
- s/old/new/ → Replaces old text with new text.
- . → Escapes the period (
.) so it is treated as a normal character. - .htm$ → Matches filenames ending exactly with
.htm. - $ → Indicates the end of the filename.
- * → Wildcard selecting all
.htmfiles.
Using the rename command simplifies bulk file management and reduces manual work in Linux environments.
If you require help, contact SupportPRO Server Admin
Partner with SupportPRO for 24/7 proactive cloud support that keeps your business secure, scalable, and ahead of the curve.
