LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

perl-rename

renames files using Perl regular expressions

TLDR

Rename with regex substitution
$ perl-rename 's/old/new/' [*.txt]
copy
Lowercase filenames
$ perl-rename 'y/A-Z/a-z/' [*]
copy
Uppercase filenames
$ perl-rename 'y/a-z/A-Z/' [*]
copy
Add prefix
$ perl-rename 's/^/prefix_/' [*]
copy
Add suffix before extension
$ perl-rename 's/(\.\w+)$/_suffix$1/' [*]
copy
Preview changes (dry run)
$ perl-rename -n 's/old/new/' [*.txt]
copy
Replace spaces with underscores
$ perl-rename 's/ /_/g' [*]
copy
Remove numbers from names
$ perl-rename 's/\d//g' [*]
copy

SYNOPSIS

perl-rename [-n] [-v] [-f] expression [files]

DESCRIPTION

perl-rename renames files using Perl regular expressions. It's more powerful than basic mv for batch renaming.The expression modifies the $_ variable containing the filename. Common operations use s/// for substitution and y/// for transliteration.Perl's full regex syntax is available: character classes, backreferences, lookahead, and more. Multiple -e expressions chain together.Dry run mode (-n) shows changes without performing them. Always use this first to verify complex expressions.The tool handles special characters, spaces, and Unicode in filenames. Quoting expressions prevents shell interpretation.Different systems may call this command rename, prename, or file-rename. The underlying functionality is the same.

PARAMETERS

-n, --no-act

Dry run, show what would happen.
-v, --verbose
Show renames as they occur.
-f, --force
Overwrite existing files.
-0, --null
Read null-terminated filenames from stdin.
-d, --filename
Rename filename only, not directory.
-e EXPR
Expression (can use multiple).
--version
Show version.
--help
Show help.

INSTALL

sudo pacman -S perl-rename
copy

CAVEATS

Expression errors can rename files incorrectly. Use -n first. May conflict with util-linux rename on some systems. Requires Perl.

HISTORY

perl-rename was written by Larry Wall, creator of Perl, and is distributed as an example script. Various packaged versions exist including prename (Debian) and file-rename. It demonstrates Perl's text processing for practical file management.

SEE ALSO

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

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid