I want to list a bunch of filenames via util does input/output buffering...
So my question is: what's the proper way of doing this in bash?
find
, pipe them through a utility (let's call this util
) which outputs a new name for each input name, and then rename each file from the old name to the new.
The most basic solution would be this:
find . -print0 | while IFS= read -d '' -r old_name; do
new_name="$(echo "$file" | util)"
mv "$old_name" "$new_name"
done
The problem with this approach is that util
is too slow to fire up for each filename separately. So the solution is to launch util
only once and pipe all the filenames through this single process:
find . -print0 >old_names
util new_names
exec {old_fd}new_names &
exec {old_fd}
Asked by Tamás Zahola
(143 rep)
Feb 2, 2019, 06:43 PM
Last activity: Feb 3, 2019, 12:29 AM
Last activity: Feb 3, 2019, 12:29 AM