renaming many files
Linux for blind general discussion
blinux-list at redhat.com
Fri Jan 22 20:02:07 UTC 2021
I'm not sure which package provides the command, but if you have
rename.ul on your system, then
rename.ul "[oldText]" "newText" *
will replace the first instance of [oldText] with [newText] in every
filename in the working directory.
Naturally, you can replace * with, for example, *.txt if you only want
to rename text files.
If you just want to delete a common string, just make [newText] empty
by putting two double quotes with nothign between them.
Note: single quotes work as well for delimiting [oldText] and
[newText], and if there's a dash(-) in either [oldText] or [newText],
you'll need to include double dash(--) before them to avoid the shell
trying to read the dashes as flag markers. Do note that rename.ul also
only changes the first instance, so if you're using it to, for example
replace underscores in web safe filenames with spaces, you'll need to
run the command until all instances have been changed.
There are other rename tools out there, but rename.ul is particularly
good at removing a common prefix from a bunch of related files, which
sounds like your situation.
More information about the Blinux-list