Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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?

History

0 comment threads

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+ with shopt -s globstar enabled).
History

0 comment threads

Sign up to answer this question »