New to bash, I am trying to change the names of dozens of files as I switch over to Linux. I need something that will work recursively from the root of a directory. In my research I found something like this that I have adapted:

find /media/D_Drive/Music/ -name '*&*.*' -exec sh -c 'mv "$0" "${0%//\&/and}"' {} \;

In the above example I am trying to replace all occurences of '&' with the word 'and'.

However, running that at the CLI I get a message that amounts to the source and new filename are the same.

Is there a way to log all activity in a CLI? For instance, all of the mv commands that would occur from the above? Bash history will only log that command, not all the iterations that command will generate.

Thanks for taking the time to read this and if you can offer assistance even better.

I wonder if adding the '-v' flag to your mv command would give you what you're looking for?

Example:
find /media/D_Drive/Music/ -name '&.*' -exec sh -c 'mv -v "$0" "${0%//\&/and}"' {} \;

Aside from that, I think what I would end up doing is just using find to get the file list, and writing a bash script to iterate through the list, 'echo'ing each command as it goes.

This seems to work for me:

#!/bin/bash
find . -name "*&*" | while read file
do
  newName=`echo $file | sed 's/\&/and/g'`
  mv "$file" "$newName"
done
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.