Re: changing part of a file name
laredotornado wrote:
> Hi,
>
> In a given directory, how do I change all file names such that I
> replace the string "show" with the string "event" in the file title?
If you have bash, you could do (case-sensitive):
for name in *show*; do
# replaces first occurrence of "show"
newname="${name/show/event}"
# to replace all occurrences, uncomment next line
#newname="${name//show/event}"
mv -- "$name" "$newname"
done
This should work even if filenames have strange characters in them (or at
least seems to work in my tests; I've tried with filenames containing
quotes, newlines, * and ?).
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
|