我想检查任何特定目录中是否存在任何 DOS 文件。除了 ^M 字符之外,还有什么方法可以区分 DOS 文件和 UNIX 吗?
我尝试使用文件,但它为两者提供了相同的输出。
$ file test_file
test_file: ascii text
转换后:
$ unix2dos test_file test_file
$ file test_file.txt
test_file.txt: ascii text
如果您实际上将 Windows 换行符放入,您将看到以下输出file
:
test_file.txt: ASCII text, with CRLF line terminators
CRLF ( \r\n
, ^M
) 行尾字符是 Unix 和 DOS/Windows ASCII 文件之间的唯一区别,所以不,没有其他方法。
如果您必须fromdos
命令,您可能会尝试将其输出与原始文件进行比较:
file=test_file
fromdos < $file | cmp $file -
$?
如果fromdos
剥离任何东西,这将失败(非零) \r
。
dos2unix
可能以类似的方式使用,但我不知道它的确切语法。