0
votes

I am not able to change the file encoding of files on my ubuntu server (version: Ubuntu 18.04.5 LTS) that has XAMPP installed and is on an AWS EC2 instance. I'm logged in as root and can edit, change and delete files. I'm logged in as root and the owner of the files is root.

I tried different versions of iconv:

iconv -f US-ASCII index.php -t ISO-8859-1 > indexisoiso.php

iconv -f utf-8 -t iso-8859-1 index.php

iconv -c -f US-ASCII -t ISO-8859-1 index.php > indexindex2.php

New files are created & no errors are shown, however, when I check file encoding again ("file --mime-encoding index.php" or "chardet index.php"), it's back to US-ASCII.

I also tried to change the encoding in vim, which didn't work:

:write ++enc=iso-8859-1 index.php

I connected to my EC2 via SSH in Visual Studio. I can (after giving myself permissions) change the file encoding there and save the file. However, when I close and reopen the file, it's back to US-ASCII (actually, in VS code, it shows "UTF-8". From what I read "UTF-8" & "US-ASCII" are equal for my purposes).

Would anyone know why I can't change the encoding of files on my ubuntu server? Has anyone had similar problems?

1
What characters are the problem? Where did you read that UTF-8 and US-ASCII are equal?choroba
I'm not sure which characters are the problem. I enter the commands, it jumps to a new line in my terminal and when I check the encoding again, it is what it used to be. Same when I do it with a file that has only "hello" written in it. I try iconv, however all resulting files have "US-ASCII".Leonore
For example here: stackoverflow.com/questions/11303405/… (Quote: "ASCII is a subset of UTF-8, so all ASCII files are already UTF-8 encoded.")Leonore

1 Answers

1
votes

Since ISO-8559-1 extends ASCII and the files didn't contain any ISO-8559-1 characters, ubuntu could simply not identify it as ISO-8559-1, but rather showed ASCII. I added some ISO-8559-1 characters to a file (äöü) and ran the iconv command again. It worked: Files are shown to be encoded in ISO-8559-1 now after adding äöü characters before converting.