如何确定OS X中的文件编码? [英] How do I determine file encoding in OS X?
问题描述
我正在尝试在 TextMate 中的LaTeX文件中输入一些UTF-8字符(表示其默认编码为UTF-8),但LaTeX似乎无法理解它们.
I'm trying to enter some UTF-8 characters into a LaTeX file in TextMate (which says its default encoding is UTF-8), but LaTeX doesn't seem to understand them.
运行cat my_file.tex
在终端中正确显示字符.运行ls -al
显示了我之前从未见过的东西:文件列表旁边的"@":
Running cat my_file.tex
shows the characters properly in Terminal. Running ls -al
shows something I've never seen before: an "@" by the file listing:
-rw-r--r--@ 1 me users 2021 Feb 11 18:05 my_file.tex
(是的,我正在LaTeX中使用\usepackage[utf8]{inputenc}
.)
(And, yes, I'm using \usepackage[utf8]{inputenc}
in the LaTeX.)
我已经找到了iconv
,但这似乎无法告诉我编码是什么,只有在我弄清楚后才会转换.
I've found iconv
, but that doesn't seem to be able to tell me what the encoding is -- it'll only convert once I figure it out.
推荐答案
@
表示文件具有与之关联的扩展文件属性.您可以使用getxattr()
函数查询它们.
The @
means that the file has extended file attributes associated with it. You can query them using the getxattr()
function.
没有确定的方法来检测文件的编码.阅读此答案,它解释了原因.
There's no definite way to detect the encoding of a file. Read this answer, it explains why.
有一个命令行工具 enca ,它会尝试猜测编码.您可能要检查一下.
There's a command line tool, enca, that attempts to guess the encoding. You might want to check it out.
这篇关于如何确定OS X中的文件编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!