This is a continuation of a related but separate ask to this question: Linux: rename files in loop while only targeting the first instance of a specific character
This code works exceptionally well for me to replace the first period from filenames such as: 2022-10-07T071101.8495077Z_QueryHistory.txt
for f in *; do mv -v -- "$f" "${f/./_}"; done # replace the first .
However, I need to run this regularly on a directory and I do not want to eventually replace the file extension .txt.
How can I run this command: for f in *; do mv -v -- "$f" "${f/./_}"; done, such that it only runs if it can find two . in the filename.
for f in *; do if [[ "$f" == *.*.* ]] ; then mv -v -- "$f" "${f/./_}"; fi ; done? – frabjous Oct 07 '22 at 20:00for f in *.*.*; do if [ "$f" != '*.*.*' ] ; then mv -v -- "$f" "${f/./_}"; fi; done. If you usebashyou can simplify this and omit theif...then...fiif you useshopt -s nullglobbefore andshopt -u nullglobafter theforloop. – Bodo Oct 07 '22 at 20:02renamecommand (the Larry Wall one). – ctrl-alt-delor Oct 07 '22 at 22:08