How can I print both "before" and "after" filenames when batch-renaming files?
+3
−0
I'm trying to bulk-rename files in a directory and its subdirectories. I want to print each file's name before and after renaming, ideally on the same line in the form:
original_filename -> new_filename
Right now, my command is:
find . -type f -print -exec perl-rename -n 'regex' {} +
But this only prints the filenames before they are renamed, not after. I want to see what the new name will be for each file, so I can review changes before running for real.
How can I print both before and after filenames (e.g. before -> after) when batch renaming files?
1 answer
+2
−0
perl-rename -nv 'regex' **/*
Breakdown:
- -n: Dry run—no files are actually renamed; it only shows what would happen.
- -v: Verbose—prints each renaming operation.
- 'regex': Your Perl regex describing how names should change.
-
**/*: Expands to all files in the current directory and all its subdirectories (requires your shell to support globstar, e.g., Bash 4+ withshopt -s globstarenabled).

0 comment threads