LinuxCommandLibrary

repren

Rename files and replace text with patterns

TLDR

Rename with pattern

$ repren --rename --from "[old]" --to "[new]" [files]
copy
Replace in files
$ repren --from "[search]" --to "[replace]" [files]
copy
Using patterns file
$ repren --patterns [patterns.txt] [files]
copy
Preview changes
$ repren --dry-run --from "[old]" --to "[new]" [files]
copy
Case preserving
$ repren --preserve-case --from "[foo]" --to "[bar]" [files]
copy
Literal strings
$ repren --literal --from "[text]" --to "[replacement]" [files]
copy

SYNOPSIS

repren [--rename] [--from pattern] [--to pattern] [options] files

DESCRIPTION

repren is a versatile batch tool for renaming files and performing search-and-replace operations across multiple files using regular expressions or literal patterns. It can apply several replacement rules simultaneously from a patterns file, making it efficient for large-scale refactoring tasks like renaming variables, updating imports, or reorganizing file structures.
A key feature is case-preserving replacement, which automatically maintains the capitalization style of the original text. For example, replacing "foo" with "bar" will also convert "Foo" to "Bar" and "FOO" to "BAR". The --dry-run flag shows all planned changes without modifying any files, allowing safe verification before committing to batch operations.
The tool supports both file content replacement and file/directory renaming with the --rename flag. Patterns can use full Python regular expressions with capture groups, or literal strings with --literal for straightforward substitutions.

PARAMETERS

--rename

Rename files/directories.
--from PATTERN
Search pattern.
--to PATTERN
Replacement pattern.
--patterns FILE
Patterns from file.
--dry-run
Preview only.
--preserve-case
Match case style.
--literal
Literal strings.
-r, --recursive
Recursive operation.

CAVEATS

Python required. Complex patterns need care. Backup important files.

HISTORY

repren was created as a versatile renaming and replacement tool supporting complex batch operations with pattern files.

SEE ALSO

rename(1), sed(1), perl(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community