24 January 2018

Renaming a bunch of files in Linux to make them contain SEO keywords


Some files are like

blah-815x338.png
blah2-300x800.png

And we want them renamed to

blah--LIST-OF-KEYWORDS-815x338.png
blah2--LIST-OF-KEYWORDS-300x800.png


You can do that with
# rename  -n   's/(-[0-9]*x[0-9]*\.[png,jpg,jpeg,gif])/--LIST-OF-KEYWORDS$1/' *


And some other files were like:

aaaaaa.jpg
eeeeeeee.png
whatever.gif

And we want them like

aaaaaa--LIST-OF-KEYWORDS.jpg
eeeeeeee--LIST-OF-KEYWORDS.png
whatever--LIST-OF-KEYWORDS.gif


You can do that with:
# find .  | grep -v "LIST-OF-KEYWORDS" | cut -b 3- | while read file ; do echo $file;rename     's/(\.[png,jpg,jpeg,gif])/--LIST-OF-KEYWORDS$1/' "$file"  ; done


Hope it helps.

0 Comments:

Post a Comment

<< Home

Too Cool for Internet Explorer