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.

5 Years
Discussion Span
Last Post by chris.stout

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

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:

find . -name "*&*" | while read file
  newName=`echo $file | sed 's/\&/and/g'`
  mv "$file" "$newName"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.