Skip to content

Instantly share code, notes, and snippets.

@afternoon
Created February 15, 2014 18:04
Show Gist options
  • Save afternoon/9022899 to your computer and use it in GitHub Desktop.
Save afternoon/9022899 to your computer and use it in GitHub Desktop.
Rename .js files to .ts
find app/src -name "*.js" -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \;
@jps1st
Copy link

jps1st commented Jun 18, 2019

Thanks :)

@abhijeet1403
Copy link

Thanks for the gist.

@kiwenlau
Copy link

Thanks

@SerhiyZheliznjak
Copy link

Thank you kindly

@medington
Copy link

Handy, but if you are using files in version control use:

find src -name "*.js" -exec sh -c 'git mv "$0" "${0%.js}.ts"' {} \;

@kylanhurt
Copy link

Beautiful!

@alan345
Copy link

alan345 commented Jan 27, 2020

great!

@nephlin7
Copy link

thanks, works perfectly.

@j33n
Copy link

j33n commented Mar 2, 2020

FYI: If you want to change jsx to tsx also, the command would become as follows
find app/src -name "*.jsx" -exec sh -c 'mv "$0" "${0%.jsx}.tsx"' {} \;

@thibaultboursier
Copy link

Thanks!

@sagar-gavhane
Copy link

How to rename .ts to .js?

@davestewart
Copy link

Nice!

I needed to pre-filter to only certain folders using globs:

find **/background/**/*.js -name "*.js" -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \;

Run a test first with just the find:

find **/background/**/*.js

@vdhand-xactly
Copy link

Thanks a lot!

@pito-svk
Copy link

pito-svk commented Jun 1, 2021

Thanks!

@KeziahMoselle
Copy link

Thank you !

@FunctionDJ
Copy link

Just what i needed

@pmnord
Copy link

pmnord commented Jan 3, 2022

This one works, thanks!

@farmeroy
Copy link

This is great. How could I make it so it will only change .js files that begin with capital letters or follow a certain regex pattern?

@gpincheiraa
Copy link

Thanks!

@jailsonpaca
Copy link

thanks!

@jesualdo13
Copy link

Thanks!

@blukanov-newsuk
Copy link

find . -path ./node_modules -prune -o -name "*.js" -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \;

if your sources are in ./ and you must skip node_modules

@Wiz-Amit
Copy link

Wiz-Amit commented Oct 1, 2022

I had to do

find app/src -name "*.js" -exec sh -c 'mv "${0}" "${0/js/ts}"' {} \;

@rafalkrol-xyz
Copy link

Thank you very much indeed!

@kishanthachat
Copy link

+1, Thanks mate!

@ther0y
Copy link

ther0y commented Jan 30, 2023

+1, Thanks

@mkajs
Copy link

mkajs commented Jun 30, 2023

nice

@AlonBruQuali
Copy link

Worked a charm, thanks

@iverenshaguy
Copy link

Thanks!

@giacomorebonato
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment