LinuxCommandLibrary

repren

Rename files using regular expressions

TLDR

Do a dry-run renaming a directory of PNGs with a literal string replacement

$ repren [[-n|--dry-run]] --rename --literal --from '[find_string]' --to '[replacement_string]' [*.png]
copy

Do a dry-run renaming a directory of JPEGs with a regex
$ repren --rename [[-n|--dry-run]] --from '[regex]' --to '[replacement_string]' [*.jpg] [*.jpeg]
copy

Do a find-and-replace on the contents of a directory of CSV files
$ repren --from '[([0-9]+) example_string]' --to '[replacement_string \1]' [*.csv]
copy

Do both a find-and-replace and a rename operation at the same time, using a pattern file
$ repren [[-p|--patterns]] [path/to/patfile.ext] --full [*.txt]
copy

Do a case-insensitive rename
$ repren --rename [[-i|--insensitive]] [[-p|--patterns]] [path/to/patfile.ext] *
copy

SYNOPSIS

The `repren` command does not have a standard synopsis.

Common `rename` (Perl version) synopsis:
rename [options] expression replacement file...

Common `rename` (util-linux version) synopsis:
rename [options] from to file...

PARAMETERS

Perl-based `rename` options:
    

-v, --verbose
    Show files successfully renamed and provide verbose output of actions.

-n, --no-act
    Perform a dry run; print what would be done without actually renaming any files.

-f, --force
    Force overwrite of existing files without prompting for confirmation.

-s, --symlink
    Operate on the target of symbolic links, rather than the links themselves.

-k, --keep-going
    Continue processing other files even if an error occurs during renaming.

Util-linux `rename` options:
    

-v, --verbose
    Display verbose information about each successful or failed renaming operation.

-n, --no-act
    Perform a dry run; print what would be done without actually renaming any files.

-f, --force
    Force overwrite of existing files without prompting for confirmation.

-i, --interactive
    Prompt before overwriting an existing file to prevent accidental data loss.

DESCRIPTION

The `repren` command is not a standard utility found in most Linux distributions. Its name, however, strongly suggests a function of 'REPlace' and 'RENaming' files. This task is commonly handled by the `rename` command, which comes in two primary versions on Linux systems: the Perl-based `rename` (often `prename` or `perl-rename`) and the simpler `util-linux` `rename` (sometimes `rename.ul`). Both allow for batch renaming of files based on pattern matching and substitution, often using regular expressions.

If `repren` were to exist, it would likely combine or enhance capabilities similar to these existing, widely used file renaming tools.

CAVEATS

The command name `rename` exists in two distinct forms on Linux, leading to frequent confusion and syntax errors. The Perl-based version (often preferred for complex tasks) offers powerful regular expression capabilities, while the `util-linux` version provides simpler string replacement. Users must verify which `rename` version is installed on their system (e.g., by checking `man rename` or `which rename`) to apply the correct syntax. `repren` itself is not a recognized command.

USAGE EXAMPLES (FOR `RENAME`)

Perl-based `rename` (e.g., using `s/old/new/` regex syntax):
rename 's/jpg/jpeg/' *.jpg
Renames all files ending with .jpg to .jpeg.

rename 's/foo/bar/gi' *
Replaces all occurrences of 'foo' (case-insensitive) with 'bar' in all filenames in the current directory.

Util-linux `rename` (e.g., using `old new` string replacement syntax):
rename jpg jpeg *.jpg
Renames all files with 'jpg' in their name to 'jpeg'.

rename ' ' '_' *.txt
Replaces the first occurrence of a space with an underscore in filenames ending with .txt.

HISTORY

While `repren` has no known history or official development, the `rename` command has evolved significantly. The original `rename` utility, part of the `util-linux` project, offered basic string replacement functionality. Later, a more powerful Perl-based `rename` script (often named `prename` or `perl-rename` in some distributions) gained widespread adoption due to its full regular expression support. This made complex batch renaming operations significantly easier and more flexible than simple string substitution, allowing for sophisticated pattern matching. Many modern Linux systems often symlink `rename` to this Perl version to provide advanced capabilities by default.

SEE ALSO

mv(1), cp(1), ln(1), find(1), sed(1)

Copied to clipboard