Skip to content

Instantly share code, notes, and snippets.

@evz
Last active May 11, 2020 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evz/4995992 to your computer and use it in GitHub Desktop.
Save evz/4995992 to your computer and use it in GitHub Desktop.
Re encode all files in a directory tree. (requires recode)
# Find encoding
find . -type f | xargs -0 -I {} echo "{}" | xargs -I {} file -bi {}
# Re-encode
find . -type f | xargs -0 -I {} echo "{}" | xargs -I {} recode ISO-8859-1..UTF-8 {}
@evz
Copy link
Author

evz commented Feb 20, 2013

Default Windows encoding is CP1252/CR-LF

@nick-petrovsky
Copy link

nick-petrovsky commented May 11, 2020

Google show this answer really often, my suggestion is to avoid middle xargs and use -print0 if you call -0 xargs option:

Forward transfrom to unicode

$ find . -type f -print0 | xargs -t -0 -n 1 recode CP1251/CR-LF..UTF-8

Inverse one

$ find . -type f -print0 | xargs -t -0 -n 1 recode UTF-8..CP1251/CR-LF

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