开发者

Checking for DOS files on UNIX

I want to check whether any DOS files exist in any specific directory. Is there any way to distinguish DOS files from UNIX apart from the ^M chars ?

I tried using file, but it gives the same output for both.

$ file test_file
test_file: ascii text

And after conversion:

$ u开发者_运维知识库nix2dos test_file test_file
$ file test_file.txt
test_file.txt: ascii text


The CRLF (\r\n, ^M) line endings chars are the only difference between Unix and DOS/Windows ASCII files, so no, there's no other way.

What you might try if you have to fromdos command is to compare its output with the original file:

file=test_file
fromdos < $file | cmp $file -

This fails (non-zero $?) if fromdos stripped any \r away.

dos2unix might be used in a similar way, but I don't know its exact syntax.


If you actually put Windows newlines in, you'll see the following output from file:

 test_file.txt: ASCII text, with CRLF line terminators
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜