First change directory to the one containing the files you wish to bulk rename:
cd /Users/tony/Downloads/Mexico/
Example of files inside of a directory:
tony@Tonys-MacBook-Air Mexico % ls -1
122 - Mexico - 45674856477658.jpg
123 - Mexico - 75934757979557.jpg
124 - Mexico - 75385739579753.jpg
125 - Mexico - 39579375938789.jpg
126 - Mexico - 73473957397593.jpg
127 - Mexico - 43749375937998.jpg
128 - Mexico - 49374937593999.jpg
129 - Mexico - 94375973583958.jpg
We are looking to remove everything but the unique string and the file extension at the end.
For example "125 - Mexico - 39579375938789.jpg" would turn into "39579375938789.jpg".
Lets try return a list of our files with a find command (from inside the directory with the files):
find . -type f -name '*.jpg'
The list appears correctly now pipe into while loop with:
find . -type f -name '*.jpg' | while read FILE ; do
newfile="$(echo ${FILE} | sed 's/^[^-]* - //' | sed 's/^[^-]* - //')" ;
mv "${FILE}" "${newfile}" ;
done
After the above is run all the files will be renamed to my desired format. This is particularly useful if there are 100's of files.
Explanation:
Notes: