You don't need rename
here, just do:
find . -name output.txt -type f -execdir mv -T output.txt output_modified.txt ';'
The -T
is a GNU extension. Without it a mv output.txt output_modified.txt
could rename output.txt
to output_modified.txt/output.txt
if there was already a directory called output_modified.txt
.
Here rename
could be useful in that it can rename more than out file at once, so could make it more efficient than calling one mv
per file, but you'd need:
to make sure your rename
is one of the perl-based ones, not the dumb one in util-linux
. It's sometimes called file-rename
or prename
or perl-rename
.
Invoke it as:
find . -name output.txt -type f -exec rename '
s|\.txt\z|_modified.txt|' {} +
With the {} +
form so find
passes more than one at a time to rename
.
Some variants of perl-based rename
s can also take the list of files to rename NULL delimiited on stdin, so with those, you could also do:
find . -name output.txt -type f -print0 |
rename -0 's|\.txt\z|_modified.txt|'
.
in the replacement text, as that is not interpreted as RegEx. – AdminBee Mar 30 '23 at 15:57util-linux
implementation – steeldriver Mar 30 '23 at 16:12