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"' {} \;
@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!

@Igor-Golub
Copy link

Thanks!

@Thomas0642
Copy link

thanks my man

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