我想检查任何特定目录中是否存在任何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
答案 0 :(得分:0)
如果您实际放入了Windows换行符,则会看到file
的以下输出:
test_file.txt: ASCII text, with CRLF line terminators
答案 1 :(得分:0)
CRLF(\r\n
,^M
)行结尾字符是Unix和DOS / Windows ASCII文件之间的唯一区别,所以不,没有别的办法。
如果必须fromdos
命令,可以尝试将其输出与原始文件进行比较:
file=test_file
fromdos < $file | cmp $file -
如果$?
剥离任何fromdos
,则失败(非零\r
)。
dos2unix
可能会以类似的方式使用,但我不知道它的确切语法。