LinuxCommandLibrary

mren

Rename multiple files using search and replace

SYNOPSIS

mren [file...]

PARAMETERS

[file...]
    A list of files to be renamed. If no files are specified, mren uses the files in the current directory.

DESCRIPTION

The mren command provides an interactive way to rename multiple files. It operates by opening a text editor containing the list of files to be renamed. The user then edits this list, changing the filenames as desired. Upon saving and closing the editor, mren executes the necessary mv commands to perform the renames. This approach makes it easy to perform complex renaming tasks that would be difficult or impossible with simple command-line tools. It is especially useful for tasks like bulk renaming based on patterns or rearranging filenames.
mren relies on the user's preferred text editor (defined by the $EDITOR environment variable) to handle the editing. If $EDITOR is not defined, vi is often used as the default. If a file is renamed to an existing file name, the user is prompted for input to avoid unintentionally overwriting an existing file. The program will rename the file, skip it, or exit. mren provides a safe way to perform mass renames.

CAVEATS

If a file is renamed to an existing file name, the user is prompted for input to avoid unintentionally overwriting an existing file. If $EDITOR is not set, the system default text editor will be invoked.

WORKFLOW

mren works by first generating a list of the specified files. It then launches the user's preferred text editor with this list loaded. The user then modifies the list within the editor, changing filenames as desired. After saving and exiting the editor, mren processes the modified list, executing the corresponding mv commands to perform the renames.
This process makes mren a valuable tool for complex renaming tasks that involve intricate patterns or require manual adjustment.

SEE ALSO

mv(1), rename(1)

Copied to clipboard