rnm
Rename multiple files using patterns
TLDR
Replace a search string with a replacement string in filenames
Use a fixed (literal) search and replace string instead of regex
Add an auto-incremented index to filenames starting from 1
Rename files using a list of new names from a text file
Rename only files (ignoring directories and links)
Sort input files by modification time before renaming
Run a simulation without making actual changes
Undo the last renaming operation
SYNOPSIS
rename [options] 'expression' files
PARAMETERS
-v
Verbose: Shows which files were successfully renamed.
-n
No-action: Prints the names of the files that would be renamed without actually renaming them. This is a dry-run mode to test the expression.
-f
Force: Overwrites existing files during the rename operation, if a file already has the target name.
-e 'command'
Executes a perl command. Multiple commands can be specified.
DESCRIPTION
The `rename` command is a powerful tool used to rename multiple files based on Perl regular expressions. It iterates through a list of files and applies the provided Perl expression to each filename. The expression typically uses substitutions (s/old/new/) to modify the names. This command allows for complex and flexible renaming operations that would be difficult or impossible with standard `mv`.
CAVEATS
Care must be taken when using regular expressions, especially when overwriting existing files. It's advisable to use the `-n` option for a dry run before executing the actual rename.
EXAMPLES
Example 1: Replace all `.jpeg` extensions with `.jpg`:
`rename 's/\.jpeg$/\.jpg/' *.jpeg`
Example 2: Convert filenames to lowercase:
`rename 'y/A-Z/a-z/' *`
Example 3: Remove spaces from filenames:
`rename 's/ //g' *`