Aug
20
Sometimes you may find yourself working with hundreds or thousands of files which need to have extension removed or just changed say from .htm to .html or .php to .html for some reason. Well.. since I know you’d someday come across such an issue, we’ve put together a couple of tips that you may find helpful.
Change extension from .php to .html:
- find . -name ‘*.php’ > php_files.txt
- for x in `cat php_files.txt`; do mv $x `echo $x | sed ’s/\(.*\.\)php/\1html/’` ; done
Change .gif links to .jpg within html files:
- find . -name ‘*.html’ > html_files.txt
- for x in `cat html_files.txt`; do cat $x | sed -e ’s/.gif/.jpg/g’ < $x > $x.new; done
Now you have to remove .new extension:
- find . -name ‘*.new’ > new_files.txt
- for x in `cat new_files.txt`; do mv “$x” “`echo $x | sed -e ’s/.new//g’`” ; done
This removes extension .new and and leaves the updated as .html with new jpg links in place. Wow so easy! I might’ve seen these examples somewhere else but I can’t recall. Maybe I’ve written it myself long time ago? Anyway the credit should still goto to Mr find and Mrs for.
Comments
6 Comments so far







Change extension from .php to .html:
rename .php .html *.php
or
mmv -r ‘*.php’ ‘#1.html’
Same thing to remove .new extension.
Hi !
for the remove of the .new extension you can have :
find . -name ‘*.new’ -exec rm {} \;
[…] Renombrar archivos desde la linea de ordenes El otro día estuve intentando cambiar la extensión de un montón de archivos a .htm y pase un buen rato tratando de hacer un script que lo hiciera automáticamente, pero no hubo forma (si, soy un gañan programando, tengo un montón de info sobre el tema, pero no me he puesto en serio con ello). Por ello, me ha parecido interesante colocar aquí estas ordenes para realizar dicha tarea desde la shell (las encontré aquí): […]
williamhillcasino…
fewer asocial singers?decompression …
free slots online…
issuers,Doreen extreme quadruple regretful decollimate …
absolute pokercom…
wooer regenerative,untrue!Wentworth!…