file-rename
Rename files
TLDR
View documentation for the original command
SYNOPSIS
rename [options] expression replacement file...
PARAMETERS
expression
The string to search for within filenames.
replacement
The string to replace the expression with.
file...
One or more files to be renamed. Wildcards are supported.
-v, --verbose
Display a list of files successfully renamed.
-n, --no-op, --test
Perform a dry run; show what would be renamed without actually doing it. Highly recommended to prevent unintended changes.
-f, --force
Overwrite existing destination files without prompting.
-i, --interactive
Prompt before overwriting an existing file.
-h, --help
Display help information and exit.
-V, --version
Display version information and exit.
DESCRIPTION
The rename command, part of the util-linux package and sometimes found as `file-rename` or `rename.ul`, provides a straightforward way to rename multiple files by replacing a specific string within their names. Unlike its Perl-based counterpart, this version performs a simple string substitution: it finds the first occurrence of an `expression` in each filename and replaces it with a `replacement` string. This utility is particularly useful for simple, repetitive renaming tasks across many files, such as changing file extensions or correcting common typos in a series of names. It operates directly on the provided filenames and does not support regular expressions or recursive directory traversal. Users should exercise caution, especially when overwriting existing files, and are encouraged to use the dry-run option first.
CAVEATS
It is crucial to distinguish this util-linux `rename` (sometimes `file-rename` or `rename.ul`) from the more common and powerful Perl-based `rename` command (often just `rename` or `perl-rename`).
The util-linux version performs only a simple string substitution on the first occurrence of the `expression`. It does NOT support regular expressions.
Always use the `-n` (dry-run) option first to verify the intended changes before executing the command, especially when dealing with critical files or large batches.
DIFFERENCES FROM 'MV'
While `mv` renames individual files or moves them to a new directory, `rename` is designed for batch operations where a specific string pattern needs to be changed across multiple filenames. `mv` requires you to specify each new name individually (or move to a new directory), whereas `rename` automates the renaming based on a rule.
CHECKING YOUR 'RENAME' VERSION
To determine which `rename` command your system uses by default, you can execute `type rename` or `which rename`. If it points to `/usr/bin/rename` (or similar) and `man rename` shows a Perl-based documentation, then you have the more powerful version. If `man rename` shows a simpler man page (or `man rename.ul`), it's likely the util-linux version.
BASIC USAGE EXAMPLE
To rename all files with `.txt.old` extension to `.txt`:
`rename ".txt.old" ".txt" *.txt.old`
This would change `document.txt.old` to `document.txt`.
HISTORY
The `rename` command on Linux systems primarily exists in two distinct implementations: the util-linux version and the Perl-based version. The util-linux variant, often compiled as `file-rename` or symlinked as `rename.ul`, focuses on basic string replacement. This simpler tool has been part of system utilities for a long time. Concurrently, a much more flexible `rename` utility written in Perl emerged, providing powerful regular expression capabilities. This dual existence means users must often check which `rename` binary is invoked by default (e.g., via `type rename`) to understand its exact behavior and capabilities.