Search code examples
macosrenamebatch-rename

Remove all non-numeric characters in a file name


I have a large number of files that are named in the format: ABC_XYZ_123.jpg.

I want to rename them in bulk so that I can get the format: 123.jpg.

How can I do this on a Mac?

Thanks!


Solution

  • Using find in terminal:

    find . -type f -name "*_*_*.jpg" -execdir bash -c 'mv "$0" "${0##*_}"' {} \; 
    

    Would result in:

    ABC_XYZ_123.jpg -> 123.jpg