LinuxCommandLibrary

prename

TLDR

Rename with Perl expression

$ prename 's/old/new/' [*.txt]
copy
Dry run
$ prename -n 's/pattern/replacement/' [files]
copy
Lowercase filenames
$ prename 'y/A-Z/a-z/' [*]
copy
Remove spaces
$ prename 's/ /_/g' [*]
copy
Add prefix
$ prename 's/^/prefix_/' [*]
copy
Add suffix before extension
$ prename 's/(\.[^.]+)$/_suffix$1/' [*]
copy
Verbose output
$ prename -v 's/old/new/' [files]
copy

SYNOPSIS

prename [-n] [-v] [-f] expression files

DESCRIPTION

prename (Perl rename) renames files using Perl expressions. It provides powerful pattern-based renaming.
The s/// substitution operator replaces text. Global flag g replaces all occurrences.
Transliteration y/// transforms character sets. Useful for case changes.
Perl code can use $_ for filename. Complex transformations are possible.
Dry run shows what would happen. Always test patterns before applying.
Multiple expressions chain transformations. Each -e adds another operation.

PARAMETERS

-n, --no-act

Dry run, show changes.
-v, --verbose
Show renames.
-f, --force
Overwrite existing files.
-0, --null
Null-separated input.
-e EXPR
Expression to apply.
-E EXPR
Like -e but without warnings.

CAVEATS

Perl syntax required. May conflict with util-linux rename. Use full path if needed.

HISTORY

prename was written by Larry Wall (creator of Perl) and is often distributed as rename with Perl. It's distinct from the simpler util-linux rename command.

SEE ALSO

rename(1), mv(1), mmv(1), perl(1)

Copied to clipboard