I was looking for a linux command line one-liner to rename a bunch of files in one shot.
pattern1.a pattern1.b pattern1.c ...
Once the command is executed I should get
pattern2.a pattern2.b pattern2.c ...
To rename multiple files from File Explorer, select all the files you wish to rename, then press the F2 key. The name of the last file will become highlighted. Type the new name you wish to give to every file, then press Enter.
You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.
for i in pattern1.*; do mv -- "$i" "${i/pattern1/pattern2}"; done
Before you run it, stick an echo
in front of the mv
to see what it would do.
If you happen to be using Linux, you may also have a perl script at /usr/bin/rename (sometimes installed as "prename") which can rename files based on more complex patterns than shell globbing permits.
The /usr/bin/rename on one of my systems is documented here. It could be used like this:
rename "s/pattern1/pattern2/" pattern1.*
A number of other Linux environments seem to have a different rename
that might be used like this:
rename pattern1 pattern2 pattern1.*
Check man rename
on your system for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With