I was recently trying to go through a directory recursively and copy all the files named file.jpg to newfile.jpg in the same local directory as the original.
I found a way to do that but it's a bit cumbersome and I have reasons to believe it is probably not the best way to go. I thought I would ask before putting this into a script.
Here is what I have so far:
cd top_of_source_dir
#copy all file.jpg and append 'newfile.jpg' to the name
find ./ -type f -name file.jpg -exec cp '{}' '{}newfile.jpg' \;
#rename the newly created files to 'newfile.jpg'
find ./ -type f -name 'file.jpgnewfile.jpg' -exec rename file.jpgn n '{}' \;
Does anyone have a recipe to do that in one iteration of the source directory?
for f in *.jpg; do echo "$f" "new${f%.*}.jpg"; doneChangeechotomvif you are sure the output is correct.find ./ -type f -name '*.jpg' -exec bash -c 'for f; do n="new${f##*/}"; echo "$f" -> "${f%/*}/$n"; done' _ {} +Again replaceechoby 'mv` if you thinkk the result is correct->I put there. It was just to visualize the action