gedit can't recognize character encoding, but gvim can
iconv
is probably what you'll want to use. iconv -l
will show you the available encodings and then you can use a couple of commands to recode them all:
# all text files are in ./originals/
# new files will be written to ./newversions/
mkdir -p newversions
cd originals
for file in *.txt; do
cat $file | iconv -f ASCII -t utf-8 > ../newversions/$file;
done
If you want to do this with files you don't the encoding of (because they're all over the place), you want to bring in a few more commands: find
, file
, awk
and sed
. The last two are just there to process the output of file.
for file in find . -type f -exec file --mime {} \; | grep "ascii" | awk '{print $1}' | sed s/.$//; do
...
I've no idea if this actually works so I certainly wouldn't run it from anything but the least important directory you have (make a testing folder with some known ASCII files in). The syntax of find might preclude it from being within a for loop. I'd hope that somebody else with more bash experience could jump in there and sort it out so it does the right thing.
Gedit can detect the correct character set only if it is listed at "File-Open-Character encoding". You can alter this list but keep in mind that the order is important.