Linux – Rename ‘:2f’ to ‘-‘ on folder names in Linux

linuxregexUbuntu

I've got a hard drive taken from a NAS drive where files had been put on from a Mac – However, some of the filenames had been, for example, 'backup 16/07/14' which has then been changed to 'backup 16:2f07:2f14' on the NAS.

This is proving an issue when copying files over to a new NAS. So what i'm looking to do is just switch the ':2f' to '-' by running a command on a folder that houses all these other folders.

I'm reasonably new to Linux, so i'm stuck. I've loaded up the hard drive on ubuntu on a virtual machine.

Any suggestions?

Best Answer

If you have perl-rename aka prename:

find . -depth -name "*:*" -exec perl-rename 's/:2f/-/g' {} +

Without:

find . -depth -name "*:*" |
while read -r name; do
    mv -nT "$name" "${name//:2f/-}"
fi
Related Question