查找具有 Linux 行结尾的所有文本文件
Find all text files with Linux line endings
我想对我的所有源文件使用 Windows 行结尾 (CRLF),但有时会混入 Linux 行结尾,例如当 Git 配置不正确时。
如何轻松找到具有 Linux 行结尾 (LF) 的所有文本文件?
使用 Cygwin 的可读性好的解决方案是:
find . -not -path '*/.*' -type f | xargs file | grep text | grep -v CRLF
解释:
-not -path '*/.*'
:过滤掉所有以.
开头的目录(例如.git
和.vs
)
-type f
:只考虑文件(不考虑目录)
xargs file
:应用file
命令判断文件类型
grep text
: 只考虑文本文件(file
包含字符串 text
所有文件)
grep -v CRLF
:过滤掉Windows行结尾 的文件
注意:要查找具有 Windows 行结尾的所有文件,只需删除 -v
:
find . -not -path '*/.*' -type f | xargs file | grep text | grep CRLF
我想对我的所有源文件使用 Windows 行结尾 (CRLF),但有时会混入 Linux 行结尾,例如当 Git 配置不正确时。
如何轻松找到具有 Linux 行结尾 (LF) 的所有文本文件?
使用 Cygwin 的可读性好的解决方案是:
find . -not -path '*/.*' -type f | xargs file | grep text | grep -v CRLF
解释:
-not -path '*/.*'
:过滤掉所有以.
开头的目录(例如.git
和.vs
)-type f
:只考虑文件(不考虑目录)xargs file
:应用file
命令判断文件类型grep text
: 只考虑文本文件(file
包含字符串text
所有文件)grep -v CRLF
:过滤掉Windows行结尾 的文件
注意:要查找具有 Windows 行结尾的所有文件,只需删除 -v
:
find . -not -path '*/.*' -type f | xargs file | grep text | grep CRLF