Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rename .js files to .ts
find app/src -name "*.js" -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \;
@matiishyn

This comment has been minimized.

Copy link

@matiishyn matiishyn commented Aug 31, 2018

thanks it works

@mzvast

This comment has been minimized.

Copy link

@mzvast mzvast commented Jan 8, 2019

Thanks, It works like magic~

@nahtnam

This comment has been minimized.

Copy link

@nahtnam nahtnam commented Jan 15, 2019

Works perfectly

@sw-yx

This comment has been minimized.

Copy link

@sw-yx sw-yx commented Feb 1, 2019

+1

@jmporchet

This comment has been minimized.

Copy link

@jmporchet jmporchet commented Apr 2, 2019

Will this overwrite existing files?

@LeandroPereiraDaCruz

This comment has been minimized.

Copy link

@LeandroPereiraDaCruz LeandroPereiraDaCruz commented Apr 8, 2019

+1

@steelx

This comment has been minimized.

Copy link

@steelx steelx commented Apr 29, 2019

works :)

@anirudh9654

This comment has been minimized.

Copy link

@anirudh9654 anirudh9654 commented May 28, 2019

Nice

@jps1st

This comment has been minimized.

Copy link

@jps1st jps1st commented Jun 18, 2019

Thanks :)

@abhijeet1403

This comment has been minimized.

Copy link

@abhijeet1403 abhijeet1403 commented Aug 20, 2019

Thanks for the gist.

@kiwenlau

This comment has been minimized.

Copy link

@kiwenlau kiwenlau commented Aug 29, 2019

Thanks

@SerhiyZheliznjak

This comment has been minimized.

Copy link

@SerhiyZheliznjak SerhiyZheliznjak commented Sep 24, 2019

Thank you kindly

@medington

This comment has been minimized.

Copy link

@medington medington commented Dec 11, 2019

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

This comment has been minimized.

Copy link

@kylanhurt kylanhurt commented Dec 22, 2019

Beautiful!

@alan345

This comment has been minimized.

Copy link

@alan345 alan345 commented Jan 27, 2020

great!

@nephlin7

This comment has been minimized.

Copy link

@nephlin7 nephlin7 commented Jan 28, 2020

thanks, works perfectly.

@j33n

This comment has been minimized.

Copy link

@j33n 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

This comment has been minimized.

Copy link

@thibaultboursier thibaultboursier commented Apr 3, 2020

Thanks!

@sagar-gavhane

This comment has been minimized.

Copy link

@sagar-gavhane sagar-gavhane commented Jun 8, 2020

How to rename .ts to .js?

@davestewart

This comment has been minimized.

Copy link

@davestewart davestewart commented Jun 18, 2020

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment