Batch / String Rename Part of File Names

Issue: On CentOS server, after migration of a WordPress website, all image names still retained old filenames. An example:

105FileName-6.jpg
105FileName-34.jpg
105FileName-33.jpg
105FileName-32.jpg
105FileName-31.jpg

105FileName-30.jpg
105FileName-29.jpg
105FileName-23.jpg
105FileName-22.jpg
etc…

and file names need to change this convention:

15AnotherName-6.jpg
15AnotherName-34.jpg
15AnotherName-33.jpg
15AnotherName-32.jpg
15AnotherName-31.jpg
15AnotherName-30.jpg

15AnotherName-29.jpg
15AnotherName-23.jpg
15AnotherName-22.jpg
etc…

Solution:

SSH into server as root, and navigate to the appropriate owner (website account) for: /public_html/wp-content/uploads/xxxx/xx

Then issue the command (which uses the above file name example) with the syntax as:

for f in 105FileName*.jpg; do mv -v "$f" "${f/105FileName/15AnotherName}"; done;

Leave a comment

BlogLogistics