How to know the encoding of a file (OS X 10.9.5)

Some OS X apps like Textedit do store the file encoding of the files as an attribute named: “com.apple.TextEncoding“.

Find out if the file has attributes defined

First we open the terminal and go where our file is located. Once we are in the right folder use the ls command:

ls -la

You may see something like this:

-rw-r--r--@  1 root  group1  4337433 17 Oct 16:30 example.txt

Pay attention to the “@” character next to the permissions. That means that some attributes have been defined for the file so it’s quite likely that the file encoding is one of them.

Show me the encoding!

Just run the following command:

file -I example.txt

This may work as well:

 xattr -p com.apple.TextEncoding example.txt

Leave a Reply

Your email address will not be published. Required fields are marked *