Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在UNIX上检查DOS文件_Unix_Dos2unix - Fatal编程技术网

在UNIX上检查DOS文件

在UNIX上检查DOS文件,unix,dos2unix,Unix,Dos2unix,我想检查任何特定目录中是否存在任何DOS文件。 除了^M字符外,还有什么方法可以区分DOS文件和UNIX文件 我尝试使用file,但它为这两个文件提供了相同的输出 $ file test_file test_file: ascii text 转换后: $ unix2dos test_file test_file $ file test_file.txt test_file.txt: ascii text 如果您实际将Windows换行符放入,您将看到文件中的以下输出: test_file.

我想检查任何特定目录中是否存在任何DOS文件。 除了^M字符外,还有什么方法可以区分DOS文件和UNIX文件

我尝试使用file,但它为这两个文件提供了相同的输出

$ file test_file
test_file: ascii text
转换后:

$ unix2dos test_file test_file
$ file test_file.txt
test_file.txt: ascii text

如果您实际将Windows换行符放入,您将看到
文件中的以下输出:

 test_file.txt: ASCII text, with CRLF line terminators

如果您实际将Windows换行符放入,您将看到
文件中的以下输出:

 test_file.txt: ASCII text, with CRLF line terminators
CRLF(
\r\n
^M
)行尾字符是Unix和DOS/Windows ASCII文件之间的唯一区别,因此没有其他方法

如果必须使用命令,您可以尝试将其输出与原始文件进行比较:

file=test_file
fromdos < $file | cmp $file -
file=test\u文件
fromdos<$file | cmp$file-
如果从DOS
剥离任何
\r
,此操作将失败(非零
$?

dos2unix
可能以类似的方式使用,但我不知道它的确切语法。

CRLF(
\r\n
^M
)行结尾字符是Unix和DOS/Windows ASCII文件之间的唯一区别,因此没有其他方法

如果必须使用命令,您可以尝试将其输出与原始文件进行比较:

file=test_file
fromdos < $file | cmp $file -
file=test\u文件
fromdos<$file | cmp$file-
如果从DOS
剥离任何
\r
,此操作将失败(非零
$?


dos2unix
可能以类似的方式使用,但我不知道它的确切语法。

不是在每个版本的Unix上。不是在每个版本的Unix上。