rename.ul
Rename multiple files using Perl expressions
SYNOPSIS
rename.ul [options] expression file...
The expression is typically a Perl-compatible substitution expression like s/pattern/replacement/[flags].
PARAMETERS
-v, --verbose
Print the names of files successfully renamed.
-n, --no-act, --dry-run
Do not make any changes; just print what would be renamed. This is highly recommended for testing expressions before actual execution.
-f, --force
Overwrite existing destination files without prompting.
-i, --interactive
Prompt before overwriting an existing destination file.
-k, --keep-basename
Do not replace the directory path if it is part of the filename. Only the basename is subject to renaming.
-o, --no-overwrite
Do not overwrite existing destination files. This is the default behavior if neither -f nor -i is specified.
-d, --dirs
Operate on directories, not just files. By default, 'rename.ul' only renames non-directory files.
--version
Display version information and exit.
--help
Display a help message and exit.
DESCRIPTION
rename.ul is a powerful command-line utility for renaming multiple files or directories based on a regular expression. Unlike mv (which renames one file at a time or moves files), rename.ul allows you to apply a substitution rule across many files simultaneously, making it ideal for bulk renaming tasks. It uses Perl-compatible regular expressions (PCRE) for its renaming logic, typically in the format s/old/new/. This means you can define complex patterns to match parts of filenames and replace them with new content, including capturing groups and various regex modifiers. While incredibly versatile, its power also means it can cause significant, irreversible changes if used incorrectly. It's an essential tool for system administrators and power users needing advanced file manipulation capabilities. It is part of the util-linux project and often symlinked from the more generic rename command.
CAVEATS
1. Power and Risk: rename.ul is extremely powerful due to its use of Perl regular expressions. Incorrectly formed expressions can lead to unintended renames, accidental overwrites, or even data loss. Always use the -n (--no-act) option to test your renaming expression before executing it.
2. rename Command Variations: Be aware that there are multiple rename commands in Linux. The rename.ul command typically refers to the version included with the util-linux package, which is designed to be compatible with the Perl rename script syntax (s/old/new/). Other distributions or installations might have a different rename command (e.g., from Perl). Always consult the specific man page for the rename command you are using.
3. No Directory Creation: rename.ul only renames existing files or directories; it does not create new directory structures as part of the rename process. For example, renaming file.txt to newdir/file.txt will fail if newdir does not exist.
THE <I>EXPRESSION</I> ARGUMENT
The core of rename.ul's power lies in the expression argument, which is typically a Perl-compatible substitution regular expression. This takes the form s/pattern/replacement/[flags].
pattern: This is a regular expression that defines what to search for within the filenames. It can include special characters, character classes, and capturing groups (e.g., (.*)).
replacement: This is the string that will replace the matched pattern. It can include backreferences (e.g., \1, \2) to refer to the content captured by groups in the pattern.
flags (optional): These are single-letter modifiers that change the behavior of the substitution. Common flags include:
- g: Global replacement (replace all occurrences of the pattern, not just the first).
- i: Case-insensitive matching.
- s: Treat string as a single line (dot `.` matches newline).
- x: Extended regex format (ignore whitespace in pattern, allow comments).
Example: To rename all files ending with .jpeg to .jpg, you would use: rename.ul 's/\.jpeg$/\.jpg/' *.jpeg
SAFETY FIRST: ALWAYS USE <I>--NO-ACT</I>!
Given the destructive potential of rename.ul, it is paramount to always test your commands using the -n or --no-act option first. This option performs a dry run, printing exactly what renames would occur without actually modifying any files. Only after verifying the output of the dry run matches your intent should you remove the -n option and execute the command for real. This simple step can prevent irreversible data loss or chaotic file organization.
HISTORY
rename utility has a long and somewhat fragmented history in the Linux ecosystem. The most prominent version, whose syntax rename.ul largely replicates, originated as a Perl script written by Larry Wall (the creator of Perl) often referred to as prename or Perl rename. This script gained popularity for its powerful regular expression capabilities, far surpassing the simple renaming of mv(1). The util-linux project, a collection of essential system utilities, later adopted its own implementation of rename that aims to be compatible with the Perl script's s/old/new/ syntax. rename.ul is specifically the name given to this util-linux version, differentiating it from potentially other rename implementations on a system. Its development has focused on providing a robust, standard utility for bulk file renaming using advanced pattern matching.