rn — A Fast, Safe, Intent-Aware Rename Utility
rn is a small command-line tool for renaming files by inference.
You provide the new name, and rn determines the old name — safely, predictably, and fast.
It streamlines common workflows like:
- Changing file extensions:
data.txt→data.csv - Adding tags or versions:
file.txt→file_backup.txt - Creating backups:
Makefile→Makefile.bak
How rn Works
rn uses two complementary matching strategies to infer which file you want to rename:
1. Extension Change
Matches when the base name is identical but the extension differs.
Examples:
Rules:
- Both files must have an extension (contain a dot)
- Everything before the last dot must match exactly
- Only the extension part differs
2. Expansion
Matches when characters are added in the middle or end of the filename.
Examples:
Rules:
- The new name must be longer than the old name
- All characters from the old name must appear in order (prefix + suffix match)
- Characters are added in the middle or at the end
- Expansion at the start is not allowed (prevents ambiguous matches)
Safety Requirements
For any rename to succeed:
- Exactly one file must match — no guessing among multiple candidates
- Target must not exist — unless
--forceis used - At least one pattern must match — extension change OR expansion
Examples
Extension Changes
Adding Tags or Versions
Backup Patterns
Bidirectional Renames
# Expansion
# Reduction (reverse expansion)
Ambiguous Cases & Limitations
⚠️ Multiple Matches (Refused)
When multiple files could match, rn refuses to guess:
Solution: Be more specific or rename manually with mv.
⚠️ Similar Extensions (May Match Both Patterns)
Some renames match both extension change AND expansion:
# Matches extension change: config.(yml) → config.(yaml)
# Also matches expansion: config.yml → config.yaml (yml is prefix of yaml)
# Result: Works fine! (we use OR logic)
This is harmless — the rename succeeds either way.
⚠️ No Prefix Expansion
rn does NOT match when adding a prefix:
# Rejected: expansion at the start is not allowed
Rationale: Prevents ambiguous matches like data.json matching metadata.json.
⚠️ Files Without Extensions
Extension change requires both files to have extensions:
⚠️ Overlapping Names
Be careful with files that are substrings of each other:
# May match test.txt via expansion (test → tester)
Best Practice: In directories with many similar names, verify the match before confirming.
Options
)
Safety Guarantees
- No wild guessing: Requires exactly one matching file
- No overwrite: Refuses if the target already exists (unless
--force) - No ambiguity: Prints all candidates and exits when multiple files match
- Atomic rename: Uses the OS rename syscall for safe file operations
rn is designed for interactive use and safety, not for risky batch scripts.
Installation
Or build from source:
Why rn?
- Faster than
mv: No need to type both the old and new names - Intent-aware: Understands common rename patterns (extensions, tags, backups)
- Safe by default: Won't rename if there's any ambiguity
- Simple: Just type the name you want,
rnfigures out the rest
mv requires you to know both names.
rn lets you rename using the name you want, not the name you must type.
Fast for humans, safe by design.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
See LICENSE file for details.